Skip to content

Instantly share code, notes, and snippets.

@gregspurrier
Created December 23, 2011 21:39
Show Gist options
  • Save gregspurrier/1515426 to your computer and use it in GitHub Desktop.
Save gregspurrier/1515426 to your computer and use it in GitHub Desktop.
Hash#without
class Hash
# Returns a new hash that does not contain the specified keys
#
# {:a => 1, :b => 2, :c =>3, :d => 4}.without(:a, :b)
# => {:c=>3, :d=>4}
def without(*keys)
dup.tap { |h| keys.each { |k| h.delete(k) } }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment