Method: Enumerable#select

Defined in:
enum.c

#find_all {|obj| ... } ⇒ Array #select {|obj| ... } ⇒ Array #find_allObject #selectObject

Returns an array containing all elements of enum for which block is not false (see also Enumerable#reject).

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

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

Overloads:

  • #find_all {|obj| ... } ⇒ Array

    Yields:

    • (obj)

    Returns:

  • #select {|obj| ... } ⇒ Array

    Yields:

    • (obj)

    Returns:



# File 'enum.c'

/*
 *  call-seq:
 *     enum.find_all {| obj | block }  -> array
 *     enum.select   {| obj | block }  -> array
 *     enum.find_all                   -> an_enumerator
 *     enum.select                     -> an_enumerator
 *
 *  Returns an array containing all elements of <i>enum</i> for which
 *  <em>block</em> is not <code>false</code> (see also
 *  <code>Enumerable#reject</code>).
 *
 *  If no block is given, an enumerator is returned instead.
 *
 *
 *     (1..10).find_all {|i|  i % 3 == 0 }   #=> [3, 6, 9]
 *
 */

static VALUE
enum_find_all(VALUE obj)
{
    VALUE ary;

    RETURN_ENUMERATOR(obj, 0, 0);

    ary = rb_ary_new();
    rb_block_call(obj, id_each, 0, 0, find_all_i, ary);

    return ary;
}