Skip to content

Instantly share code, notes, and snippets.

@tekkub
Created December 9, 2011 23:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tekkub/1453879 to your computer and use it in GitHub Desktop.
Save tekkub/1453879 to your computer and use it in GitHub Desktop.
Convert a ruby array into a hash
# Convert an array into a hash
#
# Example:
# -> [["bear", "rawr"], ["tanuki", "nuts"]].to_hash
# => {"tanuki"=>"nuts", "bear"=>"rawr"}
class Array
def to_hash
Hash[*self.flatten]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment