--001636c5b68025afcd046775cdb9 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit > For some reason, when I run the code below: > > class TEST > def initialize(args) > @args rgs > end > def describe > return @args.join(", ") > end > end > > > def test > old 0,0,0,0,0,0] > tests ] > 5.times do |i| > new ld > new[rand(old.size)] and(5) # randomly changes one of the members > of the array to a number from 0 to 4 > tests[i] EST.new(new) > puts tests[i].describe > end > return tests > end > > I get this output: > > 0, 0, 0, 0, 0, 0 > 0, 0, 0, 0, 0, 1 > 0, 0, 0, 0, 0, 4 > 0, 0, 0, 2, 0, 4 > 0, 0, 1, 2, 0, 4 > [#<TEST:0x3f3d9f0 @args , 0, 1, 2, 0, 4]>, > #<TEST:0x3f3d9d8 @args , 0, 1, 2, 0, 4]>, > #<TEST:0x3f3d900 @args , 0, 1, 2, 0, 4]>, > #<TEST:0x3f3d828 @args , 0, 1, 2, 0, 4]>, > #<TEST:0x3f3d750 @args , 0, 1, 2, 0, 4]>] When you set 'new ld', you're just creating another reference to the same array. To copy the array, use 'new ld.dup'. (dup uplicate) --001636c5b68025afcd046775cdb9--