Topic: Diff between two hashes

Maybe the title is a bit misleading as it must not explicitly be hashes I have to compare but it can be any data type, but as Rails params are hashes this seems to me straightforward.

I need to track the difference between different versions of a document.
So I started with the recipe 59 from the Rails Recipe book and I am now storing the needed parts of the params in a text field in the DB.

I now would like to ask for the most convenient approach to compare these values in order to store only the difference of two values.

What is the most convenient data type for comparing ? Hashes, arrays, yaml objects ?

Or is iterating over hashes and comparing each key and value the only (and cumbersome) way ?

Re: Diff between two hashes

I think placing the contents of the file in an array of lines is a good way to go, then you can find the difference between two arrays like this:

arr1 = [1, 2, 3]
arr2 = [1, 3, 7]
(arr1 | arr2) - (arr1 & arr2) # => [2, 7]

Railscasts - Free Ruby on Rails Screencasts

Re: Diff between two hashes

Thanks for the hints ryan.