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

前端 未结 5 1553
执笔经年
执笔经年 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条回答
  •  情歌与酒
    2020-11-27 14:39

    The API docs now describe this behaviour:

    Ranges constructed using .. run from the beginning to the end inclusively. Those created using ... exclude the end value.

    -- http://ruby-doc.org/core-2.1.3/Range.html

    In other words:

    2.1.3 :001 > ('a'...'d').to_a
     => ["a", "b", "c"] 
    2.1.3 :002 > ('a'..'d').to_a
     => ["a", "b", "c", "d"] 
    

提交回复
热议问题