Created
July 17, 2018 14:11
-
-
Save carlosbaraza/6a3547e94a0a14356549b595919b9012 to your computer and use it in GitHub Desktop.
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
deep_symbolize_keys = lambda do |hash| | |
return hash unless hash.is_a?(Hash) | |
Hash[ hash.map do |key, value| | |
# if value is array, loop each element and recursively symbolize keys | |
if value.is_a? Array | |
value = value.map { |element| symbolize_keys.call(element) } | |
# if value is hash, recursively symbolize keys | |
elsif value.is_a? Hash | |
value = symbolize_keys.call(value) | |
end | |
[key.to_sym, value] | |
end ] | |
end | |
deep_symbolize_keys.call(params) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment