Created
July 15, 2011 15:36
-
-
Save walkindude/1084916 to your computer and use it in GitHub Desktop.
Comparing hashes based on their keys
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
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