The all method allows you to pass each element of the collection to the block. The result will only be true if none of the items in the array evaluate to false or nil.
>> ["bar", "hi"].all? {|word| word.length > 2}
=> false
>> ["bar", "hi"].all? {|word| word.length >= 2}
=> true
About Paul
Paul works for Kyan web design agency in Surrey, UK as a Ruby on Rails developer.
Follow Paul on Twitter
Email: paulsturgess [at] gmail.com
Got something to say?