Skip to content

Instantly share code, notes, and snippets.

@apeiros
Created July 25, 2012 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apeiros/3175552 to your computer and use it in GitHub Desktop.
Save apeiros/3175552 to your computer and use it in GitHub Desktop.
class Array
def remove(items_to_delete)
lut = Hash.new(0)
items_to_delete.each do |e| lut[e] += 1 end
result = []
each do |e|
if lut[e] > 0
lut[e] -= 1
else
result << e
end
end
result
end
def remove!(*args)
replace(remove(*args))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment