Created
March 29, 2013 16:28
-
-
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
This file contains hidden or 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 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