2011-01-29 36 views

cevap

18

Range.step kullanmayı deneyin:

Ruby 1.9 olarak
> (1..19).step(3).to_a 
=> [1, 4, 7, 10, 13, 16, 19] 
4

:

1.step(12).to_a #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] 
1.step(12,3).to_a #=> [1, 4, 7, 10] 

Yoksa uyarısı yerine to_a ait olabilir:

a = *1.step(12,3) #=> [1, 4, 7, 10] 
+0

Gerçekten doğru birden almak isterdim cevaplar – NullVoxPopuli

İlgili konular