From: Robert Dober Date: 2006-06-27T01:38:56+09:00 Subject: Re: Ruby and Java equality usage ------=_Part_51099_28787344.1151339930396 Content-Type: text/plain; charset=WINDOWS-1252; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 6/26/06, Robert Klemme wrote: > > 2006/6/26, Robert Dober : > > > I don't fully agree to your point. Basically =3D=3D and eql? are meant t= o > implement object equivalence. So if you implement =3D=3D you should be > implementing eql? and hash, too. And usually =3D=3D and eql? should > behave the same. The page you mention quotes "For objects of class > Object, eql? is synonymous with =3D=3D. Subclasses normally continue this > tradition, but there are exceptions.". Numbers make a suble difference > here: Are you sure you read the page correctly? I copy paste: obj =3D=3D other =3D> true or false obj.equal?(other) =3D> true or false obj.eql?(other) =3D> true or false Equality=97At the Object = level, =3D=3D returns true only if *obj* and *other* are the same object. Typicall= y, this method is overridden in descendent classes to provide class-specific meaning. Unlike =3D=3D, the equal? method should never be overridden by subclasses: = it is used to ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ determine object identity (that is, a.equal?(b) iff a is the same object as b). The eql? method returns true if *obj* and *anObject* have the same value. Used by Hash to test members for equality. For objects of class Object, eql? is synonymous with =3D=3D. Subclasses normally continue this tradition= , but there are exceptions. Numerictypes, for ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ example, perform type conversion across =3D=3D, but not across eql?, so: 1 =3D=3D 1.0 #=3D> true 1.eql? 1.0 #=3D> false Now unless this is wrong, one can conclude that * #equal? shall not be redefined, * #eql? should not be redefined, unless 1's knowing what one's doing (not 4 me ;=3D) but * #=3D=3D can be redefined freely. >> 1 =3D=3D 1.0 > =3D> true > >> 1.eql? 1.0 > =3D> false Personally I find this situation a bit odd. I'd prefer a single > equivalence relation per class not two. Although I do not feel the same that seems a normal concern, as I pointed out to the OP. Honestly I think it depends on the programming culture we are coming from and when in our mind these are synonyms we are likely to get bitten by that kind of code. I can only offer you my sympathy not my agreement. But if we discuss this long enough it will become completely engraved in ou= r minds in we will be aware of it even if we do not like it ;) Cheers Robert Kind regards > > robert > > -- > Have a look: http://www.flickr.com/photos/fussel-foto/ > > ------=_Part_51099_28787344.1151339930396--