Mike Austin's Blog

Saturday, October 21, 2006

Ruby's "select"

> (1..10).select { |n| n * n if n % 2 == 0 }
[2, 4, 6, 8, 10]

In Smalltalk, "select" expects True or False. But since Ruby has "false" and everything else is "true", this allows you to return a value instead.