Does eql? do a deep comparison of objects?

Discussion in 'Ruby' started by Wes Gamble, Dec 29, 2006.

  1. Wes Gamble

    Wes Gamble Guest

    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/.
    Wes Gamble, Dec 29, 2006
    #1
    1. Advertising

  2. Wes Gamble

    Wes Gamble Guest

    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/.
    Wes Gamble, Dec 29, 2006
    #2
    1. Advertising

  3. 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
    Robert Klemme, Jan 1, 2007
    #3
  4. Wes Gamble

    Wes Gamble Guest

    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/.
    Wes Gamble, Jan 1, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Albretch
    Replies:
    9
    Views:
    5,309
    Michael Borgwardt
    Sep 10, 2004
  2. Daryl Spitzer

    Deep comparison of sets?

    Daryl Spitzer, Nov 7, 2007, in forum: Python
    Replies:
    2
    Views:
    254
    Marc 'BlackJack' Rintsch
    Nov 7, 2007
  3. Just Another Victim of the Ambient Morality

    Why does the eql? method exist?

    Just Another Victim of the Ambient Morality, Oct 19, 2006, in forum: Ruby
    Replies:
    2
    Views:
    88
    Tomasz Wegrzanowski
    Oct 19, 2006
  4. Wolfgang Nádasi-Donner

    Array#uniq - Comparison doesn't use 'eql?' and 'hash'

    Wolfgang Nádasi-Donner, Feb 20, 2007, in forum: Ruby
    Replies:
    0
    Views:
    91
    Wolfgang Nádasi-Donner
    Feb 20, 2007
  5. Wolfgang Nádasi-Donner

    Array#uniq - Comparison doesn't use 'eql?' and 'hash'

    Wolfgang Nádasi-Donner, Feb 20, 2007, in forum: Ruby
    Replies:
    3
    Views:
    130
    Daniel Finnie
    Feb 20, 2007
Loading...

Share This Page