method
delete_if

delete_if()
public
Deletes every element of self for which block evaluates to true.
The array is changed instantly every time the block is called, not after the iteration is over.
See also Array#reject!
If no block is given, an Enumerator is returned instead.
scores = [ 97, 42, 75 ] scores.delete_if {|score| score < 80 } #=> [97]
Register or
log in
to add new notes.
artemave -
November 9, 2010
tadman -
May 13, 2009
tadman -
November 14, 2012

10 thanks
NOT Equivalent to Array#reject!
@tadman is wrong. There is a difference and, trust me, it can bite:
1.9.2 > [1,2,3,4].delete_if {|x| x > 10} => [1, 2, 3, 4] 1.9.2 > [1,2,3,4].reject! {|x| x > 10} => nil
That is, if reject! hasn’t rejected anything, it returns nil.

3 thanks
Equivalent to Array#reject!
This method is functionally identical to Array#reject!

0 thanks
What artemave said.
I’d remove my original note if I could, but I can’t see a way how.