Created
February 3, 2014 16:06
-
-
Save joshm1/8786737 to your computer and use it in GitHub Desktop.
simple symbolize_keys alternative without ActiveSupport
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
# recursively symolizes keys in a Hash that are strings | |
# does not modify the original hash; returns a new hash | |
def symbolize_keys(hash) | |
hash.to_a.reduce({}) do |acc, (key, val)| | |
val = symbolize_keys(val) if val.is_a?(Hash) | |
key = key.to_sym if key.is_a?(String) | |
acc[key] = val | |
acc | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment