Chris Mendez in Ruby, For Developers

Ruby Enumberable

I doubt many people will need this but here are a few neat things you can do with Ruby. I won't go into great detail but it's methods like these that have me still loving ruby for its elegance.

Anything in your collection will satisfy a given condition

[1,2,3,4,5].any?(&:even?) #true

Use all to determine if all items in your collection fulfill that condition

[1,2,3,4,5].all?(&:even?)

Use find to get the first item in that collection to meet your condition

[1,2,3,4,5].find?(&:even?)

Use reject as the opposite of select. Anything that met your criteria, was excluded from your list

[1,2,3,4,5].reject?(&:even?)