Created
June 8, 2014 08:33
-
-
Save dv/dc23d97d798f98b6070c to your computer and use it in GitHub Desktop.
Returns the difference between two hashes, much like ActiveRecord attribute changes.
This file contains hidden or 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
def hash_diff(hash_a, hash_b) | |
hash_changes = {} | |
(hash_a.keys + hash_b.keys).uniq.each do |key| | |
if hash_a[key] != hash_b[key] | |
hash_changes[key] = [hash_a[key], hash_b[key]] | |
end | |
end | |
hash_changes | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment