# Object equivalence

**URL:** <https://www.ruby-forum.com/t/object-equivalence/110250>\
**Category:** Ruby\
**Created:** [July 24, 2007, 5:56pm UTC](https://www.ruby-forum.com/t/object-equivalence/110250 "2007-07-24T17:56:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pond](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ab992/32.png) [@pond](https://www.ruby-forum.com/u/pond)\
**Post date:** [July 24, 2007, 5:56pm UTC](https://www.ruby-forum.com/t/object-equivalence/110250/1 "2007-07-24T17:56:58Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![pond](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ab992/32.png) [@pond](https://www.ruby-forum.com/u/pond)\
**Post date:** [July 24, 2007, 8:28pm UTC](https://www.ruby-forum.com/t/object-equivalence/110250/2 "2007-07-24T20:28:48Z")

</div>

On 7/24/07, Andrew H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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
