Hi -- On Thu, 23 Nov 2006, William James wrote: > > 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. > >>> array=[1,2,3,4,5,6,7,8,9,10] > => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> array.zip(array).flatten[1..-2] > => [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10] I *still* don't feel comfortable with that one :-) The flatten thing is just too fragile. David -- David A. Black | dblack / wobblini.net Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org