From: Michael Edgar Date: 2011-08-05T02:50:51+09:00 Subject: Re: multiple array declaration using one Object::new call --Apple-Mail=_D92D5D85-AE33-47EC-BC5A-55A7FA49C829 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii On Aug 4, 2011, at 1:42 PM, Andy Davis wrote: > Hello, >=20 > I apologize if this has been covered, but I searched and could not = find > anything resembling this issue. I am fairly new to Ruby and I'm = having > a strange problem that may be my misunderstanding of how Ruby works. >=20 > I am trying to declare multiple arrays on one line, like such: >=20 > array1, array2, array =3D Array::new() >=20 > What happens is that the arrays are all nil and [seemingly] immutable. This is a part of ruby that can trip us all up at times. What you're = seeing here is implicit array expansion on the right-hand side. It's easiest to illustrate with a motivating example: a, b, c =3D [1, 2, 3] On the left-hand side, we have 3 variables, and on the right-hand side, = we have 1 value. The value on the right is an Array, so it is expanded into = the equivalent: a, b, c =3D 1, 2, 3 If the array isn't big enough to satisfy all the left-hand side = variables, it puts "nil" in the expanded assignment: a, b, c =3D [1, 2] becomes a, b, c =3D 1, 2, nil What you've got is equivalent to this: a, b, c =3D [ ] which becomes: a, b, c =3D nil, nil, nil by the same rule as above. For a more precisely-worded explanation of all this, see "Read Ruby", a nice online manual for Ruby 1.9: = http://ruby.runpaint.org/variables#assignment Michael Edgar adgar@carboni.ca http://carboni.ca/ --Apple-Mail=_D92D5D85-AE33-47EC-BC5A-55A7FA49C829--