Skip to content

Instantly share code, notes, and snippets.

@burke
Created July 7, 2010 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save burke/466268 to your computer and use it in GitHub Desktop.
Save burke/466268 to your computer and use it in GitHub Desktop.
module Enumerable
def map_to_hash(&block)
self.inject({}) do |acc, v|
h = block.call(v)
k = h.keys.first
acc[k] = h[k]
acc
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