Skip to content

Instantly share code, notes, and snippets.

@markalanevans
Created March 29, 2013 16:28
Show Gist options
  • Select an option

  • Save markalanevans/5271926 to your computer and use it in GitHub Desktop.

Select an option

Save markalanevans/5271926 to your computer and use it in GitHub Desktop.
Ruby Method to to convert a hash, with strings as keys, to symbols
def symbolize(obj)
return obj.inject({}){|memo,(k,v)| memo[k.to_sym] = symbolize(v); memo} if obj.is_a? Hash
return obj.inject([]){|memo,v | memo << symbolize(v); memo} if obj.is_a? Array
return obj
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment