method
delete_if
![Extensive documentation Importance_4](https://d2vfyqvduarcvs.cloudfront.net/images/importance_4.png?1349367920)
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
tadman -
May 13, 2009
tadman -
November 14, 2012
![Default_avatar_30](https://www.gravatar.com/avatar/3dda5dfd21d398021466f71f871920de?size=30&default=http://apidock.com/images/default_avatar_30.png)
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.
![Default_avatar_30](https://www.gravatar.com/avatar/b850a6cd0c0f8993fa152645ca9a7fbd?size=30&default=http://apidock.com/images/default_avatar_30.png)
3 thanks
Equivalent to Array#reject!
This method is functionally identical to Array#reject!
![Default_avatar_30](https://www.gravatar.com/avatar/b850a6cd0c0f8993fa152645ca9a7fbd?size=30&default=http://apidock.com/images/default_avatar_30.png)
0 thanks
What artemave said.
I’d remove my original note if I could, but I can’t see a way how.