Skip to content

Instantly share code, notes, and snippets.

@dv
Created June 8, 2014 08:33
Show Gist options
  • Save dv/dc23d97d798f98b6070c to your computer and use it in GitHub Desktop.
Save dv/dc23d97d798f98b6070c to your computer and use it in GitHub Desktop.
Returns the difference between two hashes, much like ActiveRecord attribute changes.
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