Ruby calls hash functions, and they return different values ββbecause they still just return the object_id object by default. You need to def hash and return something that reflects your idea of ββwhat makes the value of Obj significant.
>> class Obj2 < Obj >> def hash; t = super; p ['hash: ', t]; t; end >> end => nil >> x, y, xc, yc = Obj2.new, Obj2.new, 1, 1 => [#<Obj2:0x100302568 @c=1>, #<Obj2:0x100302540 @c=1>, 1, 1] >> p [x] | [y] ["hash: ", 2149061300] ["hash: ", 2149061280] ["hash: ", 2149061300] ["hash: ", 2149061280] [#<Obj2:0x100302568 @c=1>, #<Obj2:0x100302540 @c=1>]
Digitaloss
source share