delete

ary.delete(obj) â item or nil
ary.delete(obj) { block } â item or result of block
Instance Public methods

Deletes all items from self that are equal to obj.

Returns the last deleted item, or nil if no matching item is found.

If the optional code block is given, the result of the block is returned if the item is not found. (To remove nil elements and get an informative return value, use #compact!)

a = [ "a", "b", "b", "b", "c" ]
a.delete("b")                   #=> "b"
a                               #=> ["a", "c"]
a.delete("z")                   #=> nil
a.delete("z") { "not found" }   #=> "not found"
doc_ruby_on_rails
2015-03-30 16:20:43
Comments
Leave a Comment

Please login to continue.