On Monday 26 February 2001 15:00, Ben Tilly wrote:
> Aleksi Niemel<aleksi.niemela / cinnober.com> wrote:
>
> [...]
>
> > > If it doesn't then for the most part, the built-in
> > > functionality with "p" is good enough for me.
> >
> >I'm not entirely following you here, Ben.
> >
> >ruby -e'class Foo; attr_accessor :foo; end; f = Foo.new; f.foo=f; p f;'
> >#<Foo:0x4017aa90 @foo=#<Foo:0x4017aa90 ...>>
>
> [...]
>
> >Anyway, I know the pain you might be referring to, as for example simple
> >test for arrays does not work out:
> >
> >   ruby -e'b = ['b']; a = [b]; a << a; p a;'
> >   [[nil], [...]]
> >
> >	- Aleksi
>
> Pretty much what I was thinking of.  Also consider
> this case:
>
>     a = ["a"]
>     b = [a, a, a]
>     p b # IIRC (no interpreter to test) [["a"], ["a"], ["a"]]
>
> which gives no clue to the dangers lurking in
>
>     b[0].push "gotcha!"
>

Yes, but ...

a = ["a"]
b = [a,a.dup,a.dup]
b[0].push "gotcha!"
b[1].push "not"

seems to work.

And, interesting, as well, is:

a = ["a"]
for i in 0 .. 5
  a.push a.dup
end
a[1].push "gotcha!"

I just _know_ there has to be a fantastic use for this behavor!
(Not sure what it is yet, but I know it is there)

Regards,

Kent Starr
elderburn / mindspring.com