From: William Rutiser Date: 2010-03-20T22:07:42+09:00 Subject: Re: Version issues David Vlad wrote: > I apologize. I actually managed to get the until loops working after > some reinstalling. However, the .collect method still dosnt work and I > really want to use it. The code looks like this: > > > array = [1,2,5,7] > > array.collect do |x| > x = x*2 > end > > puts array.inspect > > > After I have run this code it still says the array is [1,2,5,7]. "array.collect " isn't supposed to modify array. "array.collect" returns a newly constructed array containing the block's results. Compare irb(main):001:0> array = [1,2,5,7] => [1, 2, 5, 7] irb(main):002:0> irb(main):003:0* array.collect do |x| irb(main):004:1* x = x*2 irb(main):005:1> end => [2, 4, 10, 14] irb(main):006:0> irb(main):007:0* puts array.inspect [1, 2, 5, 7] => nil with irb(main):008:0> array = [1,2,5,7] => [1, 2, 5, 7] irb(main):009:0> puts array.collect do |x| irb(main):010:1* x = x*2 irb(main):011:1> end 1 2 5 7 => nil irb(main):012:0> puts array.inspect [1, 2, 5, 7] => nil