Skip to content

Instantly share code, notes, and snippets.

@viebel
Last active June 20, 2016 18:21
Show Gist options
  • Save viebel/4659664 to your computer and use it in GitHub Desktop.
Save viebel/4659664 to your computer and use it in GitHub Desktop.
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