Skip to content

Instantly share code, notes, and snippets.

@awendt
Forked from edward/gist:32225
Created June 18, 2009 13:12
Show Gist options
  • Save awendt/131894 to your computer and use it in GitHub Desktop.
Save awendt/131894 to your computer and use it in GitHub Desktop.
class Hash
def except(*blacklist)
self.reject {|key, value| blacklist.include?(key) }
end
def only(*whitelist)
self.reject {|key, value| !whitelist.include?(key) }
end
end
h = {:a => 10, :b => 34, :c => "hello"}
h.only :a, :b # => {:a=>10, :b=>34}
h.except :a, :b # => {:c=>"hello"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment