Skip to content

Instantly share code, notes, and snippets.

@ncri
Last active August 4, 2017 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ncri/5661189 to your computer and use it in GitHub Desktop.
Save ncri/5661189 to your computer and use it in GitHub Desktop.
def self.symbolize_keys(hash)
hash.inject({}){|result, (key, value)|
new_key = case key
when String then key.to_sym
else key
end
new_value = case value
when Hash then symbolize_keys(value)
when Array then value.map{ |v| v.is_a?(Hash) ? symbolize_keys(v) : v }
else value
end
result[new_key] = new_value
result
}
end
@ootoovak
Copy link

ootoovak commented Sep 8, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment