From: Jia Pu Date: 2006-09-01T12:08:37+09:00 Subject: Q: How to use non-builtin class as hash key? ------=_Part_81392_30921896.1157080092736 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline I have a class defined as: ########################### class MyClass def initialize(s1, s2, s3) @string1 = s1 @string2 = s2 @string3 = s3 end def hash return (@string1 + @string2 + @string3).hash end end ########################### Then I create two instances of this class: ########################### obj1 = MyClass.new('a', 'b', 'c') obj2 = MyClass.new('a', 'b', 'c') ########################### If verify obj1 and obj2 do have the same hash value, I check that 'obj1.hash == obj2.hash' returns true Now i try to use those objects as hash key: h[obj1] = 'abc' h[obj2] = 'def' I expected h contains only one item with value 'def', since obj1 and obj2 have the same hash value. But it turns out it has 2 items instead. Did I miss something? ------=_Part_81392_30921896.1157080092736--