Skip to content

Instantly share code, notes, and snippets.

@stouset
Created January 13, 2012 21:04
Show Gist options
  • Save stouset/1608686 to your computer and use it in GitHub Desktop.
Save stouset/1608686 to your computer and use it in GitHub Desktop.
def purge_if
self.inject({}) do |hash, (key, value)|
yield(key, value) ? hash : hash.update(key => self.delete(key))
end
end
@stouset
Copy link
Author

stouset commented Jan 13, 2012

>> h
=> {:b=>2, :a=>1}
>> h.purge_if {|k,v| k == :a }
=> {:b=>2}
>> h
=> {:a=>1}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment