Hi Mauricio,

> I solved it, being more or less focused on size (but not really a lot)
> and when I was about to 'optimize' it I read that size doesn't matter :-)

Good job. I like the way you slimed it down dropping the Node tree. It seems
to make the code easier to read and maintain.

> [I assumed hashes would always be sortable with sort {|a,b|a.to_s <=>
b.to_s}
>  which is not really sensible]

I assume you mean if a hash key's to_s method outputs something blank? (For
instance on the nil object?)  Seems like you should just use inspect. Isn't
inspect always supposed to generate something intelligent?

> but iv are not here?? (You're using #inspect instead of a recursive call
to
> object_to_s)

Good call, I missed that one.

> [I corrected that to have the same format as "top level" object_to_s]
>
> >   assert_equal('[... 2, 3, ... ...]', string_a)
> >   assert_equal('[... 3, 4, ... ... 6]', string_b)
>
> In arrays, '...' is used for the first element if equal to that othe
> other array

Not sure what you mean.

> [kept that]
> >   assert_equal('{:a=>1, :b=>2, ... :d=>4}', string_a)
> >   assert_equal('{       :b=>3, ... :d=>5, :j=>2}', string_b)
>
> ... which is not the case for hashes: spaces instead???
> [changed to use '...' instead, as in arrays]

No spaces are used when the element doesn't exsist in the other object. For
example:

a = { :a => 1, :b => 2, :c => 3}
b = { :b => 2, :c => 3}

so ['{ :a => 1, ... ...}', '{         ... ...}'] would be the output of
compare for hashes. When printed on separate lines this helps to determine
what keys are missing.

The same should be true when comparing classes with different instance
variables. Although to my chagrin my test case doesn't show this and neither
does my code.

> And again, these semantics won't always work. What happens if you have
> keys from different classes, how do you get a meaningful order there?
> Perhaps sorting by class name?

Again I think sorting by key.inspect may be the best solution.

> My solution + the test case modifications are attached.
> It only passes the tests, there's a couple more things that need to
> be done for general use (just adding a couple 'when' clauses for other
> literals).

Overall a good, clean solution. I like the way you're using object_to_s to
do most of the grunt work. Two thumbs up. I hope you plan to post your code
again when it is ready for general use.

A couple of things I haven't figured out:

1. What does ruby use when outputting the object id for object.inspect?
Either I can't get the formatting right, or it's not the object id. (Compare
object_to_s with inspect.)

2. How do you handle fringe classes that are descendants of Array, Hash,
String, etc... intelligently? For instance say A < String and has an
instance variable. How do you print this and note the difference? (Or should
you even bother?)
___________________
John Long
www.wiseheartdesign.com