Deep diffing

This commit is contained in:
Arfon Smith
2014-07-07 13:23:04 -05:00
parent f7672b837a
commit a474ffc101
2 changed files with 24 additions and 0 deletions

15
lib/linguist/diff.rb Normal file
View File

@@ -0,0 +1,15 @@
class Hash
def deep_diff(b)
a = self
(a.keys | b.keys).inject({}) do |diff, k|
if a[k] != b[k]
if a[k].respond_to?(:deep_diff) && b[k].respond_to?(:deep_diff)
diff[k] = a[k].deep_diff(b[k])
else
diff[k] = [a[k], b[k]]
end
end
diff
end
end
end