Created
March 8, 2013 22:31
-
-
Save mgamba/5120453 to your computer and use it in GitHub Desktop.
get all keys of a hash, good for diffing hashes that are equivalent regardless of values
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
def nested_keys(h) | |
th = {"keys" => h.keys.sort} | |
h.each{|k,v| th[k] = nested_keys(h[k]) if h[k].class == Hash } | |
th | |
end | |
nested_keys(h1).diff(nested_keys(h2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment