On Sat, Jul 19, 2003 at 11:24:31PM +0900, John W. Long wrote:
> > >   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.

I assumed '...' meant "element equal to the one in the other array
(at the same index)". I didn't read the following right, and believed
spaces where used instead of '...' if the match was on the first item.

> > [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:

OK, I see it now. Implementing this is however quite complicated (ie.
not as easy as what I'm doing now :)

> 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.

This can get quite ugly if the iv. refers to an object whose text
representation is "big" and you have line wrapping.

> > 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.

ok

> 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.

I can clear it a bit if you want. Note that I didn't try to make it
especially clean or anything, just short (or rather not too long).

> 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.)

It uses the address of the object:

static VALUE
rb_obj_inspect(obj)
    VALUE obj;
{
    ...
	if (rb_inspecting_p(obj)) {
	    str = rb_str_new(0, strlen(c)+10+16+1); /* 10:tags 16:addr 1:nul */
	    sprintf(RSTRING(str)->ptr, "#<%s:0x%lx ...>", c, obj);
	    RSTRING(str)->len = strlen(RSTRING(str)->ptr);
	    return str;
	}
	...
	str = rb_str_new(0, strlen(c)+6+16+1); /* 6:tags 16:addr 1:nul */


> 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?)

perhaps introducing a notation like
<MyArrayClass:0x12345678 [... 1, 2, ..., 3] @a=1>

-- 
 _           _                             
| |__   __ _| |_ ___ _ __ ___   __ _ _ __  
| '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ 
| |_) | (_| | |_\__ \ | | | | | (_| | | | |
|_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
	Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

Beeping is cute, if you are in the office ;)
	-- Alan Cox