Ruby中固定次数的循环写法

固定次数的循环

times

4.times.to_a
#=> [0, 1, 2, 3]

upto

1.upto(4).to_a
#=> [1, 2, 3, 4]

1..4

same to upto

(1..4).to_a
#=> [1, 2, 3, 4]

1…4

(1...4).to_a
#=> [1, 2, 3]

Resources

https://launchschool.com/books/ruby/read/loops_iterators