Skip to content

Instantly share code, notes, and snippets.

@stefanpenner
Forked from burke/map_to_hash.rb
Created July 8, 2010 00:46
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 stefanpenner/467501 to your computer and use it in GitHub Desktop.
Save stefanpenner/467501 to your computer and use it in GitHub Desktop.
module Enumerable
def map_to_hash(&block)
self.inject({}) do |acc,v|
acc.merge(block.call(v))
end
end
end
x = [:a, :b, :c].map_to_hash do |v|
{v => v.to_s.upcase}
end
puts x.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment