Created
December 27, 2012 07:23
-
-
Save taterbase/4386288 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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