From: Robert Klemme Date: 2006-08-01T20:45:06+09:00 Subject: Re: Weird elusive bug using Comparable Pedro C�rte-Real wrote: > On 7/31/06, Robert Klemme wrote: >> > I thought date1 == date2 was the same as (date1 <=> date2> == 0 but >> > apparently not. >> >> No, it's differently implemented. > > How then? According to the docs if you implement <=> and include > Comparable you get ==. But my second assertion is failing when it > should be blowing up when trying to do nil <=> nil. You get == but if you implement it yourself your version will shadow the one from Comparable: >> class Foo >> def <=>(o) 0 end >> include Comparable >> end => Foo >> Foo.instance_method :== => # Now we add it to Foo: >> class Foo >> def ==(o) false end >> end => nil >> Foo.instance_method :== => # >> Foo.ancestors => [Foo, Comparable, Object, Kernel] Kind regards robert