Skip to content

Instantly share code, notes, and snippets.

@georgebrock
Forked from zetter/gist:295978
Created February 5, 2010 17:10
Show Gist options
  • Save georgebrock/295980 to your computer and use it in GitHub Desktop.
Save georgebrock/295980 to your computer and use it in GitHub Desktop.
class Hash
def hash_map()
self.inject({}) do |hash, (k, v)|
hash.merge(k => yield(k, v))
end
end
end
{:a => 1, :b => 2}.hash_map {|k,v| v**2 } # => {:a => 1, :b => 4}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment