Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Array#delete_if
() { (Elem item) -> ::boolish } -> self
() -> ::Enumerator[Elem, self]
delete_if {|element| ... } → self
delete_if → new_numerator
array.c
View on GitHub ↗
static VALUE
rb_ary_delete_if(VALUE ary)
{
ary_verify(ary);
RETURN_SIZED_ENUMERATOR(ary, 0, 0, ary_enum_length);
ary_reject_bang(ary);
return ary;
}
With a block given, calls the block with each element of self; removes the element if the block returns a truthy value; returns self:
Example
a = [:foo, 'bar', 2, 'bat'] a.delete_if {|element| element.to_s.start_with?('b') } # => [:foo, 2]
With no block given, returns a new Enumerator.
Related: see Methods for Deleting.