Created
July 9, 2013 01:33
-
-
Save murayama/5953961 to your computer and use it in GitHub Desktop.
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 recursive_symbolize_keys! hash | |
if hash.is_a? Hash | |
hash.symbolize_keys! | |
hash.values.each {|h| recursive_symbolize_keys! h} | |
elsif hash.is_a? Array | |
hash.map {|v| recursive_symbolize_keys! v} | |
end | |
hash | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment