-
-
Save Ladicle/b68b2a1cb1124d314670 to your computer and use it in GitHub Desktop.
Hashのキーをシンボルに変換する(全階層 & 途中配列が入っていてもok)
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 deep_symbolize_keys | |
self.each_with_object({}) do |(key, val), memo| | |
if val.is_a?(Array) | |
val = val.map{|v| v.deep_symbolize_keys} | |
elsif val.is_a?(Hash) | |
val = val.deep_symbolize_keys | |
end | |
memo[key.to_s.to_sym] = val | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment