0009 None_one_any_all

How they really work

These 4 methods are defined in Enumerable and check whether respectively none, one and only one, at least one or all elements are ‘true’. As a reminder, in Ruby only nil and false are considered ‘false’, all the rest being ‘true’. So be careful, it’s not just related to the number of elements in the Enumerable.

0009-none_one_any_all_1.png

Unlike grep, a proc is used with a block to realize complex conditions.

0009-none_one_any_all_2.png

And, just like grep, you can use a parameter as a pattern thanks to the === method.

0009-none_one_any_all_3.png

Finally, a little quiz: what about this edge case?

0009-none_one_any_all_4.png

Links to Ruby documentation for none?, one?, any? and all?.