Skip to content

Instantly share code, notes, and snippets.

@mgamba
Created March 8, 2013 22:31
Show Gist options
  • Save mgamba/5120453 to your computer and use it in GitHub Desktop.
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
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