Difference between '..' (double-dot) and '…' (triple-dot) in range generation?

前端 未结 5 1561
执笔经年
执笔经年 2020-11-27 14:08

I\'ve just started learning Ruby and Ruby on Rails and came across validation code that uses ranges:

validates_inclusion_of :age, :in => 21..99
validates_         


        
5条回答
  •  旧时难觅i
    2020-11-27 14:46

    That is correct.

    1.9.3p0 :005 > (1...10).to_a
     => [1, 2, 3, 4, 5, 6, 7, 8, 9]
    1.9.3p0 :006 > (1..10).to_a
     => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    

    The triple-dot syntax is less common, but is nicer than (1..10-1).to_a

提交回复
热议问题