From: Guillaume Cottenceau Date: 2001-06-23T04:38:51+09:00 Subject: [ruby-talk:16778] Re: uniq and "equivalence" Hugh Sasse Staff Elec Eng writes: [...] > > Define a #hash method for your class Trapezoidal_fitness, actually because > > it's not defined it use the default #hash function which is the id of the > > object. > > That's what I don't want, but how can one map a 4-D set > of floats on to Fixnums? Maybe I should redefine uniq: Of course you can't :-). Hash functions are used to speed things up, not to do the whole of the comparisons: irb> class T irb> def hash irb> puts "in hash" irb> 3 irb> end irb> end nil irb> a = T.new # irb> b = T.new # irb> [a,b].uniq in hash in hash [#, #] irb> class T irb> def eql?(other) irb> puts "in eql?" irb> true irb> end irb> end nil irb> a.eql?(b) in eql? true irb> [a,b].uniq in hash in hash in eql? in hash in hash [#] I suppose #hash is used first, #eql? next. (while I can't guess why #hash seems to be called twice) -- Guillaume Cottenceau - http://mandrakesoft.com/~gc/