[#1026] Is this a bug? — Dave Thomas <Dave@...>

18 messages 2000/01/03

[#1084] Infinite loop — Dave Thomas <Dave@...>

17 messages 2000/01/11

[#1104] The value of while... — Dave Thomas <Dave@...>

24 messages 2000/01/11

[ruby-talk:01087] Re: Infinite loop

From: Yasushi Shoji <yashi@...>
Date: 2000-01-11 07:07:13 UTC
List: ruby-talk #1087
From: Dave Thomas <Dave@thomases.com>
Subject: [ruby-talk:01084] Infinite loop
Date: 10 Jan 2000 18:30:20 -0600

> I don't know if this is a bug or expected behavior - I could argue it
> either way, but..

it is expected behavior as far as I can tell.  The method Array#=, or
should I say method Array#[]=(?), takes the reference of a, not a copy
of a.  you can use Array#dup to create a copy of a to insert to a[1].

$ ruby -e "a=[1,2,3]; a[1]=a.dup; p a"
[1, [1, 2, 3], 3]

hope this helps,
--
          yashi

In This Thread