Unknown Iterators
So we all know the basic iterators
.each which returns the original array/hash
.map returns a new array/hash after results from block
.selects returns a new array/hash from conditional from block
.find returns the first object in array/hash based on conditional block
I myself have stuck with these for conventional logic, but as my logic changed so did my needs to render it. Enter the boolean iterator.
Get Mickey Partlow’s stories in your inbox
Join Medium for free to get updates from this writer.
.any? returns true if any truthy item is found. false if all are false/nil.
say you have collected data and you are not sure if its worth searching through. how do you know if some of the data meets your conditional.
Thats where .any? comes in handy.
.all? returns true if all items pass conditional block false if any fail.
this is a good method for proof reading your information to make sure nothing has slipped the mold.
one thing i also learned about .all? is it returns true on an empty array so if you were iterating through the array and were gradually emptying it you would have to time it by the array length not the difference in truthiness.
as to the opposite of .all? there is .none?
.none? returns true if no items pass conditional. and false if one or more pass.







