1

I tried this in my rails console.

2.0.0-p481 :012 > a = 1
 => 1 
2.0.0-p481 :013 > z = 26
 => 26 
2.0.0-p481 :014 > a..z
 => 1..26 
2.0.0-p481 :015 > a...z
 => 1...26 

What is the difference between the two?

webster
  • 3,902
  • 6
  • 37
  • 59
  • 1
    http://stackoverflow.com/questions/9690801/difference-between-double-dot-and-triple-dot-in-range-generation – Mircea Mar 05 '15 at 06:39

2 Answers2

2

A quick check:

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

Its evident ... does not include the last value i.e. its the range till n-1.

shivam
  • 16,048
  • 3
  • 56
  • 71
0

Yes, the version with two dots includes the last element, the one with three dots does not:

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

(1...4).to_a
#=> [1, 2, 3]
spickermann
  • 100,941
  • 9
  • 101
  • 131