End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Array#reject!
array.reject! {|element| ... } → self or nil
array.reject! → new_enumerator
array.c
View on GitHub ↗
static VALUE
rb_ary_reject_bang(VALUE ary)
{
RETURN_SIZED_ENUMERATOR(ary, 0, 0, ary_enum_length);
rb_ary_modify(ary);
return ary_reject_bang(ary);
}
Removes each element for which the block returns a truthy value.
Returns self if any elements removed:
Example
a = [:foo, 'bar', 2, 'bat'] a.reject! {|element| element.to_s.start_with?('b') } # => [:foo, 2]
Returns nil if no elements removed.
Returns a new Enumerator if no block given:
Example
a = [:foo, 'bar', 2] a.reject! # => #<Enumerator: [:foo, "bar", 2]:reject!>
See also
#reject
#repeated_combination
#rassoc
#repeated_permutation
also in
4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0