Skip to content

Instantly share code, notes, and snippets.

@viebel viebel/to_hash.rb
Last active Jun 20, 2016

Embed
What would you like to do?
ruby array to hash
class Array
def to_hash(&block)
Hash[*self.map {|x|
[x, block.call(x)]
}.flatten(1)]
end
end
[1,2,3].to_hash {|x|
10*x
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.