From: Rein Henrichs Date: 2010-06-11T00:30:05+09:00 Subject: Re: comparing objects 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. -- Rein Henrichs http://puppetlabs.com http://reinh.com