Skip to content

Instantly share code, notes, and snippets.

@taterbase
Created December 27, 2012 07:23
Show Gist options
  • Save taterbase/4386288 to your computer and use it in GitHub Desktop.
Save taterbase/4386288 to your computer and use it in GitHub Desktop.
class Array
def to_h
arr = self.collect do | val |
[ self.index(val), val]
end
Hash[arr]
end
end
arr = [ 'lol', 'why', 'js', 'rb' ]
puts arr.to_h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment