Skip to content

Instantly share code, notes, and snippets.

@joshm1
Created February 3, 2014 16:06
Show Gist options
  • Save joshm1/8786737 to your computer and use it in GitHub Desktop.
Save joshm1/8786737 to your computer and use it in GitHub Desktop.
simple symbolize_keys alternative without ActiveSupport
# 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