From: Avdi Grimm Date: 2012-07-14T15:21:00+09:00 Subject: Re: method clear wiping out other array ? --0016e6d99c252bc28204c4c43325 Content-Type: text/plain; charset=ISO-8859-1 Both variables point to the same array. If you want two arrays, you need to call #dup: arr2 = arr1.dup -- Avdi Grimm http://avdi.org On Jul 13, 2012 11:43 PM, "Mike Onofrietto" wrote: > Hello all, > > Need help. > See code below. The array arr2 has data to start with. > The first 2 puts show output - no problem - both the same as expected. > > The last 2 puts - no output - nothing - nada. > > Between the lines shown here there is no other code - this is exactly > what the actual code looks like. > > puts " #{arr2}" > arr1 = arr2 > puts " #{arr1}" > > arr2.clear > puts " #{arr1}" > puts " #{arr2}" > > -- > Posted via http://www.ruby-forum.com/. > > --0016e6d99c252bc28204c4c43325 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

Both variables point to the same array.

If you want two arrays, you need to call #dup:

arr2 =3D arr1.dup

--
Avdi Grimm
http://avdi.org

On Jul 13, 2012 11:43 PM, "Mike Onofrietto&= quot; <lists@ruby-forum.com&= gt; wrote:
Hello all,

Need help.
See code below. The array arr2 =A0has data to start with.
The first 2 puts show output - no problem - both the same as expected.

The last 2 puts - no output - nothing - nada.

Between the lines shown here there is no other code - this is exactly
what the actual code looks like.

puts " =A0 =A0 =A0 =A0#{arr2}"
arr1 =3D arr2
puts " =A0 =A0 =A0 =A0#{arr1}"

arr2.clear
puts " =A0 =A0 =A0 =A0#{arr1}"
puts " =A0 =A0 =A0 =A0#{arr2}"

--
Posted via http://= www.ruby-forum.com/.

--0016e6d99c252bc28204c4c43325--