# Does eql? do a deep comparison of objects?

**URL:** <https://www.ruby-forum.com/t/does-eql-do-a-deep-comparison-of-objects/80676>\
**Category:** Ruby\
**Created:** [December 29, 2006, 9:25pm UTC](https://www.ruby-forum.com/t/does-eql-do-a-deep-comparison-of-objects/80676 "2006-12-29T21:25:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [December 29, 2006, 9:25pm UTC](https://www.ruby-forum.com/t/does-eql-do-a-deep-comparison-of-objects/80676/1 "2006-12-29T21:25:01Z")

</div>

If I have two objects A and B where each is of the same type but have  
arbitrarily complex object graphs, will the result of A eql? B be false  
if ANY part of the object graph differs, no matter how deep it is?

In my specific case, A and B are ActiveRecord objects with lots of  
“has\_many” dependencies.

Thanks,  
Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [December 29, 2006, 9:30pm UTC](https://www.ruby-forum.com/t/does-eql-do-a-deep-comparison-of-objects/80676/2 "2006-12-29T21:30:47Z")

</div>

Sorry I wasted a post. I just tried this and found that eql? does not  
compare all the way down the object tree.

Does anyone know of a generic method for doing this?

Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [January 1, 2007, 5:25pm UTC](https://www.ruby-forum.com/t/does-eql-do-a-deep-comparison-of-objects/80676/3 "2007-01-01T17:25:33Z")

</div>

On 29.12.2006 21:30, Wes G. wrote:

> Sorry I wasted a post. I just tried this and found that eql? does not  
> compare all the way down the object tree.

There is no general implementation defined for eql? - every class  
decides for itself how it is done. In case a class does not implement  
it it will inherit eql? from any of its superclasses.

> Does anyone know of a generic method for doing this?

Well, you could try to traverse both object graphs and compare each  
instance. But this is pretty tedious.

What kind of problem are you trying to solve?

Kind regards

```
robert
```

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [January 1, 2007, 7:15pm UTC](https://www.ruby-forum.com/t/does-eql-do-a-deep-comparison-of-objects/80676/4 "2007-01-01T19:15:36Z")

</div>

Robert K. wrote:

> What kind of problem are you trying to solve?
> 
> Kind regards
> 
> robert

In a Rails app, I was trying to determine whether or not to take a  
particular action based on whether or not an object had been changed via  
a form. I ended up doing it in an object-specific way and it was fine.

Thanks for the help,  
Wes
