Last active
August 29, 2015 14:02
-
-
Save exAspArk/4aa5fa70acf5d492eda7 to your computer and use it in GitHub Desktop.
Nested symbolize keys (ruby)
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
def nested_symbolize_keys(thing) | |
case thing | |
when Array | |
thing.map { |value| nested_symbolize_keys(value) } | |
when Hash | |
Hash[thing.map { |key, value| [key.to_sym, nested_symbolize_keys(value)] }] | |
else | |
thing | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://api.rubyonrails.org/classes/Hash.html#method-i-deep_symbolize_keys 😆