Skip to content

Instantly share code, notes, and snippets.

@pje
Created September 22, 2012 15:49
Show Gist options
  • Save pje/3766587 to your computer and use it in GitHub Desktop.
Save pje/3766587 to your computer and use it in GitHub Desktop.
HashUtils
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