[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: object equivalence

Todd Benson

7/24/2007 6:27:00 PM

On 7/24/07, Andrew Hume <andrew@research.att.com> wrote:
> i have two objects, a and b, both of the same class.
> i believe they have the same contents, but
> a.eql?(b) returns false
>
> if i write a method xxx that returns as a string the value of every
> field
> (much as to_s does), then a.xxx.hash == b.xxx.hash.
> i believe this latter shows a and b are equivalent; o why
> doesn't eql? agree?

eql? is just a method and therefore depends on the implementing
object. By default, eql? returns true only if the objects being
compared are the _same_ object. And then, each class typically
overrides eql? to do as the developer sees fit.

Todd