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
enum.c
View on GitHub ↗
static VALUE
enum_find_all(VALUE obj)
{
VALUE ary;
RETURN_SIZED_ENUMERATOR(obj, 0, 0, enum_size);
ary = rb_ary_new();
rb_block_call(obj, id_each, 0, 0, find_all_i, ary);
return ary;
}
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.