Skip to content

Instantly share code, notes, and snippets.

@tinogomes
Created December 21, 2010 12:37
Show Gist options
  • Save tinogomes/749885 to your computer and use it in GitHub Desktop.
Save tinogomes/749885 to your computer and use it in GitHub Desktop.
To downcase all keys and subkeys from a hash
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
@tinogomes
Copy link
Author

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