what are Ranges
Ruby has ranges, with range operators and a Range class.
Ranges are intervals with a start value and an end value, separated by a range operator.
There are two range operators, .. (two dots) and ... (three dots).
The range operator .. means an inclusive range of numbers.
1..10 means a range of numbers from 1 to 10, including 10 (1, 2, 3, 4, 5, 6, 7, 9, 10).
The range operator ... means an exclusive range of numbers that exclude the last in the series;
in other words, 1...10 means a range of numbers from 1 to 9, as the 10 at the end of the range is excluded (1, 2, 3, 4, 5, 6, 7, 9).
The === method determines if a value is a member of, or included in, a range
(1..25) === 14 # => true, in range
(1..25) === 26 # => false, out of range
(1...25) === 25 # => false, out of range if ... used
Related examples in the same category