Skip to content

Instantly share code, notes, and snippets.

@heftig
Forked from havenwood/additional_hash_methods.rb
Last active December 13, 2015 19:39
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 heftig/4964533 to your computer and use it in GitHub Desktop.
Save heftig/4964533 to your computer and use it in GitHub Desktop.
class Hash
def map_value
each_pair.with_object({}) { |(key, value), result| result[key] = yield value }
end
def map_key
each_pair.with_object({}) { |(key, value), result| result[yield key] = value }
end
def map_pair(&blk)
Hash[map(&blk)]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment