From: kjana@...4lab.to (YANAGAWA Kazuhisa) Date: 2002-09-24T12:43:04+09:00 Subject: Re: Problem with x.downto(y) {} In message tokikenshi@anime-genesis.com writes: > # snip > @curLen.downto(1) do |i| > @snake[i].x = @snake[i - 1].x > @snake[i].y = @snake[i - 1].y > end > # snip > > @curLen is an integer with the value 20 and @snake is an array > containing structures for defining coordinates. The snippet above is a > part in a snake-clone where the element 0 in array @snake is the head > which is feeded with new values each cycle. This piece of code > controls the flow of coordinates for each point of the snake. I can't find problem too since the following works: arr = [1, 2, 3, 4, 5] arr.size.downto(1) {|i| arr[i] = arr[i-1]} arr[0] = 0 p arr #=> [0, 1, 2, 3, 4, 5] > Every time I run this code Ruby dies with no message at all. > Help, please! So really wanting to fix the problem, more information is needed. However this particular case, I can propose an alternative: Use Array#unshift. arr = [1, 2, 3, 4, 5] arr.unshift(0) p arr #=> [0, 1, 2, 3, 4, 5] Urgh you don't want the last element, you can kill it by Array#pop. Maybe overkilling and inefficient, but it works. -- kjana@dm4lab.to September 24, 2002 Art is long, and time is fleeting.