Created
May 6, 2010 11:37
-
-
Save StanBright/392035 to your computer and use it in GitHub Desktop.
This file contains hidden or 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_hash | |
hash = Hash.new | |
for pair in self | |
if ( pair.size == 2 and | |
pair[0].class == Symbol and | |
pair[1].class == Fixnum ) | |
hash[pair[0]] = pair[1] | |
else | |
raise ArgumentError.new "Incorrect array type" | |
end | |
end | |
hash | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment