method

find

v1_8_7_72 - Show latest stable - Class: Enumerable
find(...)
public

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

   (1..10).detect  {|i| i % 5 == 0 and i % 7 == 0 }   #=> nil
   (1..100).detect {|i| i % 5 == 0 and i % 7 == 0 }   #=> 35

4Notes

Returns the element, not block result

tadman · Apr 1, 20091 thank

Enumerable#find will always return the element that is found, not the result of the block provided.

Video Explanation of find and find_all

MattStopa · Mar 11, 2012

Example is a Bug!

rubynooby · Feb 11, 2015

Why is the example showing the use of the #detect method and not #find? Boggles the mind!

Find and Detech are the same

shimrra · Nov 17, 2015

@rubynooby: #find and #detect are aliases of the same underlying method. You can use them interchangeably to provide additional readability to your code (find an element to use it or detect if an element is present to do something).

http://ruby-doc.org/core-2.2.3/Enumerable.html#method-i-find