Method: Enumerable#reject

Defined in:
enum.c

#reject {|element| ... } ⇒ Array #rejectObject

Returns an array of objects rejected by the block.

With a block given, calls the block with successive elements; returns an array of those elements for which the block returns nil or false:

(0..9).reject {|i| i * 2 if i.even? }                             # => [1, 3, 5, 7, 9]
{foo: 0, bar: 1, baz: 2}.reject {|key, value| key if value.odd? } # => {:foo=>0, :baz=>2}

When no block given, returns an Enumerator.

Related: #select.

Overloads:

  • #reject {|element| ... } ⇒ Array

    Yields:

    • (element)

    Returns:



611
612
613
614
615
616
617
618
619
620
621
622
# File 'enum.c', line 611

static VALUE
enum_reject(VALUE obj)
{
    VALUE ary;

    RETURN_SIZED_ENUMERATOR(obj, 0, 0, enum_size);

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

    return ary;
}