From: Daniel Martin Date: 2007-07-13T22:16:04+09:00 Subject: Re: Loop over an array that changes the elements benjohn@fysh.org writes: > As others and I have said, the map solution is good here. > > numbers = numbers.map {|number| number*2} > > If you really wanted to change the array itself though, you could do this: > > numbers.each_index {|i| numbers[i] = numbers[i] * 2} Actually, as I think someone already posted, map! is probably the most idiomatic way of doing this: numbers.map! {|x| 2*x} -- s=%q( Daniel Martin -- martin@snowplow.org puts "s=%q(#{s})",s.to_a.last ) puts "s=%q(#{s})",s.to_a.last