On Thu, Aug 29, 2002 at 01:08:13PM +0900, Ryan King wrote: > On 2002.08.29, Jim Freeze <jim / freeze.org> wrote: > > Sorry to but in, but I don't understand exactly what you are > > trying to accomplish with CompareByValue. > > > > Do you want to compare any two objects? > > Are you including all the contained data as well in the compare? > > Forgive me -- you're not the only one to ask this question. > > I'll clarify (and put it on > http://www.rubygarden.org/ruby?CompareByValue for posterity). > > When you're unit-testing a class into existence, you often see > brain-dead .=='s that look like this: > > def == other > @a == other.a && @b == other.b ... > end > > This is time-consuming, and redundant. So, I want to > automate it. > > Just simply loop over all the current instance variables, > comparing them via "==", and making sure you don't screw anything > up (like get stuck in an infinite loop, or do anything that > wouldn't work with concurrency). > > To me, this is the most DWIMmy .== definition. Maybe I'm > crazy, though. > Thanks for the quick overview. I remember reading it early on, but I guess it didnt sink in. Concerning unit testing, I don't seem to use #=='s muuch on classes. I think I usually test whether functions return the right thing or not. However, I suppose that you would have to put some limitations on testing the instance variables. For example, do you trace through arrays? class MyClass def initialize(some_object) @var = [some_object] end end m1 = MyClass.new(obj1) m2 = MyClass.new(obj2) Now the m1 == m2 has to apply the #== to the contents of @var. If this was a tree class, it could be a mess. Do I understand this correctly? Hmm...I wonder if one could sort the output of Marshall.dump and compare.... -- Jim Freeze If only I had something clever to say for my comment... ~