Skip to content

Instantly share code, notes, and snippets.

@puyo
Created April 16, 2010 05:39
Show Gist options
  • Save puyo/368066 to your computer and use it in GitHub Desktop.
Save puyo/368066 to your computer and use it in GitHub Desktop.
# Is there a preferred way to do it? A lot of people I see use inject, but it makes my eyes bleed.
x = [[1, 2], [3, 4]]
p x.inject({}) { |h, r| h[r[0]] = r[1]; h }
# {1=>2, 3=>4}
p Hash[*x.flatten]
# {1=>2, 3=>4}
p Hash[x]
# {1=>2, 3=>4}
# Yay. Thanks dave.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment