From: Robert Klemme Date: 2010-06-11T01:10:06+09:00 Subject: Re: comparing objects On 06/10/2010 05:27 PM, Rein Henrichs wrote: > On 2010-06-10 06:59:40 -0700, Robert Dober said: > >> On Thu, Jun 10, 2010 at 3:41 PM, Wilson Bilkovich >> wrote: >> Even if >>> your code lives in isolation, ensuring proper semantics via these >>> methods prevents a class of tricky bug that your successors may have >>> to deal with. >> Hmm? Would you care to show an example where overloading those methods >> (#eql? and #hash) is needed to ensure proper behavior? I am willing to >> learn. But I am not willing to accept this statement as such. >> Cheers >> R. > > You have been presented with one in this very thread. The OP wants > objects of his class to have the correct semantics for Array#& and > Hash#[], etc. The correct answer is to implement #hash and #eql?, just > as implementing <=> provides objects of his class with the correct > semantics for Array#sort. See also http://blog.rubybestpractices.com/posts/rklemme/018-Complete_Class.html http://blog.rubybestpractices.com/posts/rklemme/019-Complete_Numeric_Class.html Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/