Created
December 21, 2010 12:37
-
-
Save tinogomes/749885 to your computer and use it in GitHub Desktop.
To downcase all keys and subkeys from a hash
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 Hash | |
def downcase_all_keys | |
result = self.map do |k,v| | |
[ | |
k.downcase, | |
case v.class.name | |
when "Hash" then v.downcase_all_keys | |
when "Array" then v.map {|i| i.downcase_all_keys } | |
else v | |
end | |
] | |
end | |
Hash[result] | |
end | |
end |
porque apenas downcase não fica explicito que será downcase apenas das chaves.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Porque não apenas
Hash#downcase
, já que esse método não existe para hashes? :)