Skip to content

Instantly share code, notes, and snippets.

@walkindude
Created July 15, 2011 15:36
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 walkindude/1084916 to your computer and use it in GitHub Desktop.
Save walkindude/1084916 to your computer and use it in GitHub Desktop.
Comparing hashes based on their keys
class Hash
def same_key_structure?(other)
return false unless other.is_a?(Hash)
return false unless self.keys == other.keys
return self.keys.all? do |k|
if self[k].is_a?(Hash)
self[k].same_key_structure?(other[k])
else
!other[k].is_a?(Hash)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment