Calmops
  • Categories (current)
  • Tags
  • Tools
  • By Me a Coffee

Ruby中固定次数的循环写法

2016-10-11
扫一扫获取本文链接,可在手机中查看或分享。
  • 固定次数的循环
    • times
    • upto
    • 1..4
    • 1…4
  • Resources

固定次数的循环

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

Related Articles:

  • public private protected in Ruby
  • include and extend in Ruby
  • Instance Method in Ruby
  • Include vs Extend in Ruby
  • self in ruby
©2022 Yongqiang Qu me@yongqiang.live   All Rights Reserved