Method: Enumerable#select
- Defined in:
- enum.c
#find_all {|obj| ... } ⇒ Array #select {|obj| ... } ⇒ Array #find_all ⇒ Object #select ⇒ Object
Returns an array containing all elements of enum for which the given block returns a true value.
If no block is given, an Enumerator is returned instead.
(1..10).find_all { |i| i % 3 == 0 } #=> [3, 6, 9]
[1,2,3,4,5].select { |num| num.even? } #=> [2, 4]
See also Enumerable#reject.
340 341 342 343 344 345 346 347 348 349 350 351 |
# File 'enum.c', line 340
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;
}
|