From: Wilson Bilkovich Date: 2006-11-21T13:38:26+09:00 Subject: Re: array question On 11/20/06, Li Chen wrote: > Hi all, > > I want to build a new array from an old one with every element being > duplicated except the first and last element. And here are my codes. I > wonder if this is a real Ruby way to do it. > A couple of ways: (there are probably dozens more) # given: array = [1,2,3,4,5,6] # 1. new_array = array[1..-2] # 2. new_array = array.dup new_array.shift # shifts off the first element new_array.pop # pops off the last element #1 uses Array#[], which is a synonym for Array#slice. 1..-2 is a Range parameter. In this case, it says you want a slice of the array containing everything but the first and last element.