Eric Mahurin wrote:
> --- Robert Klemme <bob.news / gmx.net> wrote:
>
>>>>>> On 10/26/05, Eric Mahurin <eric_mahurin / yahoo.com>
>> wrote:
>>>>>>> Anybody know what the best way to override inspect where you
>>>>>>> may have a recursive data structure?
>
>
>> .... which reminds me of an RCR I've been wanting to submit
>> for quite some
>> time now:
>> http://rcrchive.net/rcr/show/323
>>
>> This could help here, too.
>>
>> Kind regards
>>
>>     robert
>
> Could you describe how this could be used to override #inspect?
>  Or any other example?  I think a ruby implementation RCR would
> go a long way.

Without going into the details:

def inspect
  s = ""
  traverse(self) do |obj|
    s << "(" if Enumerable === obj
    s << do_whatever(obj)
    s << ")" if Enumerable === obj
  end
  s
end

It might even be interesting to have a second parameter which indicates
the distance from the start object.  That way indentation would be easy
and maybe it can be used for other stuff as well.  Just an idea.

Kind regards

    robert