Skip to content

Instantly share code, notes, and snippets.

@alissonsales
Created July 27, 2009 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alissonsales/156691 to your computer and use it in GitHub Desktop.
Save alissonsales/156691 to your computer and use it in GitHub Desktop.
class Hash
def diff(hash)
raise ArgumentError, 'Argument is not a Hash' unless hash.is_a? Hash
kkeys = []
self.keys.each do |k|
diff = self[k].diff(hash[k]) if self[k].is_a? Hash and hash[k].is_a? Hash
kkeys << {k => diff} if diff and diff.size > 0
end
diff = self.keys - hash.keys
kkeys << diff if diff and diff.size > 0
return kkeys
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment