Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Does eql? do a deep comparison of objects?

Reply
Thread Tools

Does eql? do a deep comparison of objects?

 
 
Wes Gamble
Guest
Posts: n/a
 
      12-29-2006
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

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Wes Gamble
Guest
Posts: n/a
 
      12-29-2006
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


--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      01-01-2007
On 29.12.2006 21:30, Wes Gamble 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
 
Reply With Quote
 
Wes Gamble
Guest
Posts: n/a
 
      01-01-2007
Robert Klemme 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


--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparison of 2 files and generating the output based on comparison Deepu Perl Misc 1 02-07-2011 03:09 PM
Price Comparison Service. Best Deal. Special Coupon atBest-Price-Comparison.com rapee Digital Photography 0 03-14-2008 06:46 AM
Deep comparison of sets? Daryl Spitzer Python 2 11-07-2007 07:39 PM
Deep Freeze In Deep Trouble johntangelo@gmail.com Computer Security 3 10-25-2005 11:49 PM
Deep comparison of two objects' graphs Albretch Java 9 09-10-2004 08:12 AM



Advertisments