Skip to content

Instantly share code, notes, and snippets.

@davissp14
Created April 25, 2013 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davissp14/5462578 to your computer and use it in GitHub Desktop.
Save davissp14/5462578 to your computer and use it in GitHub Desktop.
Symbolize each level of your hash...
#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