Does eql? do a deep comparison of objects?

W

Wes Gamble

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
 
W

Wes Gamble

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
 
R

Robert Klemme

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
 
W

Wes Gamble

Robert said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top