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.

Thank you for your input.

Li


#########
C:\>irb
irb(main):001:0> array=[1,2,3,4,5,6,7,8,9,10]
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
irb(main):002:0> array_new=Array.new
=> []
irb(main):003:0> array.each do |e|
irb(main):004:1*      array_new<<"#{e}"
irb(main):005:1>      array_new<<"#{e}"
irb(main):006:1> end
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
irb(main):007:0>
irb(main):008:0* array_new.delete_at(0)
=> "1"
irb(main):009:0> array_new.delete_at(array_new.size-1)
=> "10"
irb(main):010:0>  puts array_new
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
=> nil


-- 
Posted via http://www.ruby-forum.com/.