method
delete_if
v1_8_7_330 -
Show latest stable
- Class:
Array
delete_if()public
Deletes every element of self for which block evaluates to true.
a = [ "a", "b", "c" ] a.delete_if {|x| x >= "b" } #=> ["a"]
3Notes
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.
Equivalent to Array#reject!
This method is functionally identical to Array#reject!
What artemave said.
I'd remove my original note if I could, but I can't see a way how.