Created
September 22, 2012 15:49
-
-
Save pje/3766587 to your computer and use it in GitHub Desktop.
HashUtils
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
module HashUtils | |
def self.recursive_symbolize_keys(h) | |
case h | |
when Hash | |
Hash[ | |
h.map do |k, v| | |
[ k.respond_to?(:to_sym) ? k.to_sym : k, recursive_symbolize_keys(v) ] | |
end | |
] | |
when Enumerable | |
h.map { |v| recursive_symbolize_keys(v) } | |
else | |
h | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment