Method: Array#reject

Defined in:
array.c

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

Returns a new Array whose elements are all those from self for which the block returns false or nil:

a = [:foo, 'bar', 2, 'bat']
a1 = a.reject {|element| element.to_s.start_with?('b') }
a1 # => [:foo, 2]

Returns a new Enumerator if no block given:

a = [:foo, 'bar', 2]
a.reject # => #<Enumerator: [:foo, "bar", 2]:reject>

Overloads:

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

    Yields:

    • (element)


4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
# File 'array.c', line 4267

static VALUE
rb_ary_reject(VALUE ary)
{
    VALUE rejected_ary;

    RETURN_SIZED_ENUMERATOR(ary, 0, 0, ary_enum_length);
    rejected_ary = rb_ary_new();
    ary_reject(ary, rejected_ary);
    return rejected_ary;
}