> > 2) It doesn't work if the class has hash attribute because > > {'a' => 1}.hash != {'a' => 1}.hash > > Now that is weird. I've a faint recollection of it being mentioned on > ruby-talk before though, so perhaps its not a bug. This makes sense, as both hashes are mutable. Their contents may be the same, but they shouldn't be mistaken for the same object, as either one's value could change at any time. Consider the following: --- h = Hash.new g = Hash.new hh = h.hash gh = g.hash puts "Hashes for 'h' and 'g' are " + (hh == gh ? "equal" : "not equal") h[1] = true g[1] = false puts "Hash for 'h' has " + (hh == h.hash && "not ") + "changed" puts "Hash for 'g' has " + (gh == g.hash && "not ") + "changed" --- If you run the code above, the output should be: --- Hashes for 'h' and 'g' are not equal Hash for 'h' has not changed Hash for 'g' has not changed --- Using an object as a hash key, you want to check identity, not equality. That way, even if your object is mutable, and you use it as a key later, it will bee associated with the same value (assuming your mapping hasn't changed, of course). Lennon