-
-
Save ezekg/211b18fde10a1f3eb41a to your computer and use it in GitHub Desktop.
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
module HashExtensions | |
def symbolize_keys | |
inject({}) do |acc, (k,v)| | |
key = String === k ? k.to_sym : k | |
value = Hash === v ? v.symbolize_keys : v | |
acc[key] = value | |
acc | |
end | |
end | |
end | |
Hash.send(:include, HashExtensions) | |
hash = {"drinks"=>{"gibson"=>{"garnish"=>"onion"}, "martini"=>{"garnish"=>"olive"}}} | |
puts hash.symbolize_keys.inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment