From: Joel VanderWerf Date: 2005-10-26T12:27:14+09:00 Subject: Re: overriding #inspect Eric Mahurin wrote: > Anybody know what the best way to override inspect where you > may have a recursive data structure? For now I'm just calling > #to_s on the elements, but I would like to call #inspect > instead putting in a "..." as soon as I find a recursive loop. > I'm guessing that I need to add an instance variable to say > that I've been visited by #inspect. Or maybe go check the call > stack? Array#inspect does it somehow: irb(main):001:0> a = [] => [] irb(main):002:0> a << a => [[...]] See array.c. It looks like rb_ary_inspect() uses a table (a ruby array actually) to keep track of visited IDs. -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407