Skip to content

Instantly share code, notes, and snippets.

@Naggi-Goishi
Last active February 1, 2017 17:07
Show Gist options
  • Save Naggi-Goishi/47b37c97aa2d102b4cfec684af76ff32 to your computer and use it in GitHub Desktop.
Save Naggi-Goishi/47b37c97aa2d102b4cfec684af76ff32 to your computer and use it in GitHub Desktop.
meta-programming that add method of keys_to_sym, which convert every keys to symbol type from string.
class Hash
def keys_to_sym
self.inject({}) do |hash, (key, value)|
value = value.keys_to_sym if value.class == Hash
hash[key.to_sym] = value
hash
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment