From: "William James" <> Date: 2009-12-29T02:10:13+09:00 Subject: Re: creating array David A. Black wrote: > Hi -- > > On Mon, 28 Dec 2009, Haris Bogdanovi? wrote: > > > Hi. > > > > Is there a short way of creating array of numbers > > with, for example, step of 10, like this: > > > > 10,20,30,40,50 > > > > By short I mean without going through iteration loop: > > > > array=[] > > (1..5).each do |i| > > array.push i*10 > > end > > In 1.8.6 you can do: > > array = (1..5).map {|i| i * 10 } > > and in 1.9 you can do: > > 10.step(50,10).to_a > > I can never keep track of which side of the fence 1.8.7 falls on, but > you can try both. > > > David irb(main):001:0> 10.step(50,10).to_a => [10, 20, 30, 40, 50] irb(main):002:0> RUBY_VERSION => "1.8.7" --