From: Robert Klemme Date: 2010-06-07T05:55:10+09:00 Subject: Re: comparing objects On 05.06.2010 16:41, Robert Dober wrote: > On Sat, Jun 5, 2010 at 2:35 PM, Robert Klemme > wrote: >> On 05.06.2010 00:35, Anderson Leite wrote: >>> Before >>>> we can provide solutions we have to know what problem must be solved. >>> I have a list of objects that came from database and another list of >>> objects extracted from a xml. I need the elements who are in both lists. >>> >>> >>> Then...I thought to compare objects overriding the == method like Marcin >>> Wolski wrote. There is another solution ? >> If all objects you are dealing with implement #eql? and #hash in a way to be >> suitable for that comparison then using #eql? is the most straightforward >> approach. > Not #eql?, #== please. Why? Array#& uses #eql? - as Hash lookup methods do, too. $ ruby19 -e 'class C;def eql?(x)printf "eq %p\n",x;false;end;def hash;0;end;end;[C.new] & [C.new]' eq # Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/