From: Robin Pedersen Date: 2008-04-15T22:15:07+09:00 Subject: Re: noob 'why doesn't this work' question On Apr 14, 5:47 pm, Vincent Angeloni wrote: > Hi and greetings to all group members! > > I'm a new Ruby user with a background in Applescript, Hypertalk > (Supercard), and a little Unix. I was intrigued by Matt Neuburg's > article about Applescript and Ruby, and that's what got me reading some > intro books on Ruby. I just bought Textmate and I am lovin' it! > > Anyway, I am wondering why this seemingly simple script fails: > > sizeList = [0,1,2,3,4,5,6] > countarray = [3,4,6] > countarray.each {|x| sizeList.delete_at(x)} > > what I want to happen is that sizelist gets deleted at the positions > specified in countArray, but the result I am getting is: > > 0 > 1 > 2 > 4 > 6 > > and the expected result should be 0,1,2,5, right? > What gives? > > TIA, > vince > > Mac OS X 10.5.2, G5 Quad, Textmate editor, ruby 1.86 What about this: sizeList = [0,1,2,3,4,5,6] countarray = [3,4,6] countarray.sort.reverse.each {|x| sizeList.delete_at(x)} Result: 0,1,2,5