------ art_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 <shortcutter / googlemail.com> wrote: > > 2006/6/26, Robert Dober <robert.dober / gmail.com>: > <SNIP> > > I don't fully agree to your point. Basically == and eql? are meant to > implement object equivalence. So if you implement == you should be > implementing eql? and hash, too. And usually == and eql? should > behave the same. The page you mention quotes "For objects of class > Object, eql? is synonymous with ==. 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: <begin doc> obj == other => true or false obj.equal?(other) => true or false obj.eql?(other) => true or false <http://www.ruby-doc.org/core/classes/Object.src/M001416.html> Equality͢t the Object <http://www.ruby-doc.org/core/classes/Object.html>level, == returns true only if *obj* and *other* are the same object. Typically, this method is overridden in descendent classes to provide class-specific meaning. Unlike ==, 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 <http://www.ruby-doc.org/core/classes/Hash.html> to test members for equality. For objects of class Object<http://www.ruby-doc.org/core/classes/Object.html>, eql? is synonymous with ==. Subclasses normally continue this tradition, but there are exceptions. Numeric<http://www.ruby-doc.org/core/classes/Numeric.html>types, for ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ example, perform type conversion across ==, but not across eql?, so: 1 == 1.0 #=> true 1.eql? 1.0 #=> false <end doc> 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 ;=) but * #== can be redefined freely. >> 1 == 1.0 > => true > >> 1.eql? 1.0 > => 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 our 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/ > > ------ art_51099_28787344.1151339930396--