Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Enumerable#reject
() { (E) -> ::boolish } -> ::Array[E]
() -> ::Enumerator[E, ::Array[E]]
reject {|element| ... } → array
reject → enumerator
enum.c
View on GitHub ↗
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;
}
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:
Example
(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.