find

enum.find(ifnone = nil) { |obj| block } â obj or nil
enum.find(ifnone = nil) â an_enumerator
Instance Public methods

Passes each entry in enum to block. Returns the first for which block is not false. If no object matches, calls ifnone and returns its result when it is specified, or returns nil otherwise.

If no block is given, an enumerator is returned instead.

(1..10).detect   { |i| i % 5 == 0 and i % 7 == 0 }   #=> nil
(1..100).find    { |i| i % 5 == 0 and i % 7 == 0 }   #=> 35
doc_ruby_on_rails
2015-04-05 00:03:24
Comments
Leave a Comment

Please login to continue.