Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Enumerable#find_all

enum.find_all { |obj| block } → array
enum.find_all → an_enumerator

Returns an array containing all elements of enum for which the given block returns a true value.

The find_all and select methods are aliases. There is no performance benefit to either.

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

Example
(1..10).find_all { |i|  i % 3 == 0 }   #=> [3, 6, 9]

[1,2,3,4,5].select { |num|  num.even?  }   #=> [2, 4]

[:foo, :bar].filter { |x| x == :foo }   #=> [:foo]

See also Enumerable#reject, Enumerable#grep.

See also #find #find_index #filter_map #first also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1