Ruby : Difference between ‘..’ (double-dot) and ‘…’ (triple-dot) in range generation?

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

Note that (1..9) != (1...10), and here’s an example why:

(1..9).include?(9.5)    #=> false
(1...10).include?(9.5)  #=> true

(a..b) is like a <= x <= b, whereas (a...b) is like a <= x < b.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s