From: James Coglan Date: 2008-08-21T16:19:55+09:00 Subject: Re: each, stuck up... ------=_Part_60044_20099116.1219303416691 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline > > I did the following in irb 1.9; > a = [3, 2, 1, 0, -1, -2, -3] > a.each {|x| a[x] = x +1} > > I'm kind-a obtuse at the moment, could someone please tell me what was > it that I did wrong. > I wanted to increment the values of each element of the array. In the above example, x is the value of each member of the array, not its position. You want this instead: a.map! { |x| x + 1 } map! takes each member of an array and performs some transformation on it, writing the result back to the array. ------=_Part_60044_20099116.1219303416691--