Evaluating all items in an array in Ruby on Rails
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 is a web developer for Kyanmedia web agency. He's lucky enough to write in Ruby on Rails full-time and uses this site to post snippets of code.
Contact
my name at gmail.com
More snippets
Take a look in the archive
Need a website?
Contact my employer. Make sure to check out our portfolio of work.
Hosting
I recommend hostingrails.com
No comments have been left
Got something to say?