2009/12/28 David A. Black <dblack / rubypal.com>:
> 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=3D[]
>> (1..5).each do |i|
>> =A0 array.push i*10
>> end
>
> In 1.8.6 you can do:
>
> =A0array =3D (1..5).map {|i| i * 10 }
>
> and in 1.9 you can do:
>
> =A010.step(50,10).to_a

In fact, the #to_a might be completely superfluous depending on that
the OP wants to do with this.

> I can never keep track of which side of the fence 1.8.7 falls on, but
> you can try both.

:-)

Kind regards

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/