method
delete_if
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"]
Register or
log in
to add new notes.
artemave -
November 9, 2010
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.
tadman -
May 13, 2009
3 thanks
Equivalent to Array#reject!
This method is functionally identical to Array#reject!
tadman -
November 14, 2012
0 thanks
What artemave said.
I’d remove my original note if I could, but I can’t see a way how.