James French
3/25/2009 11:03:00 AM
Ah, I understand - thanks. My next question is - is it possible to prevent =
this?
________________________________________
From: lasitha [lasitha.ranatunga@gmail.com]
Sent: 25 March 2009 10:48
To: ruby-talk ML
Subject: Re: appending an array to a frozen array
On Wed, Mar 25, 2009 at 4:00 PM, James French
<James.French@naturalmotion.com> wrote:
> Morning all,
>
> @dependencies.freeze
> @dependencies +=3D ["blah", "blah"]
>
> does not error out due to modifying a frozen array (1.8.7 p72).
> [...]
+=3D creates a new array and assigns it to @dependencies. The original
array remains frozen but @dependencies no longer refers to it.
To illustrate:
$: irb
01> a =3D b =3D [1, 2]
--> [1, 2]
02> a.freeze
--> [1, 2]
03> b.frozen?
--> true
04> b +=3D [3, 4]
--> [1, 2, 3, 4]
05> a.frozen?
--> true
solidarity,
lasitha=