Created
April 25, 2013 19:48
-
-
Save davissp14/5462578 to your computer and use it in GitHub Desktop.
Symbolize each level of your hash...
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
#Example | |
# Input: {"first1"=>"hi", "first2"=>{"second"=>"gah", "second1"=>{"third1"=>"toot"}, "second2"=>"gah3"}} | |
# Output: {:first1=>"hi", :first2=>{:second=>"gah", :second1=>{:third1=>"toot"}, :second2=>"gah3"}} | |
def symbolize(hash) | |
temp_hash = {} | |
hash.map do |k,v| | |
temp_hash[k.to_sym] = v | |
if v.is_a?(Hash) | |
temp_hash[k.to_sym] = symbolize(v) | |
end | |
end | |
temp_hash | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment