-
-
Save duncanbeevers/299285 to your computer and use it in GitHub Desktop.
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
class Hash | |
def recursively_stringify_keys | |
recursively_xify_keys(:to_s, :recursively_stringify_keys) | |
end | |
def recursively_symbolize_keys | |
recursively_xify_keys(:to_sym, :recursively_symbolize_keys) | |
end | |
private | |
def recursively_xify_keys x, recursion | |
inject({}) do |a, (k, v)| | |
a[k.respond_to?(x) ? k.send(x) : k] = v.respond_to?(recursion) ? | |
v.send(recursion) : v | |
a | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment