If You Detect None
The Enumerable#detect
method, which is synonymous with #find
, can be given an optional argument, ifnone
, that is called when nothing in the array meets the conditional in the block. Though I am not sure how this is practically useful and cannot find an example of it in use, this contrived example illustrates how it works.
The last example can also be written as:
And if you want to be really explicit:
Last updated