Range: A Structured Type in Ruby
Ruby has a numerous structured types, comprising arrays, hashes, sets, classes, streams, and ranges. In this section we would only discuss ranges briefly as an instance of a structured type.
Range of T ADT signifies a set of values of type T (called the base type) between two extremes. Start value is a value of type T which sets the lower bound of a range, and end value is a value of type T which sets the upper bound of a range. Range itself is the set of values of type T between lower and upper bounds. For illustration, Range of Integers from 1 to 10 inclusive is the set of values {1, 2, 3, ..., 10}.
A range can be inclusive, meaning that it includes end value, or exclusive, meaning that it doesn't include the end value. Inclusive ranges are written with two dots between extremes, and exclusive ranges with three dots. Hence Range of Integers from 1 to 10 inclusive is written 1...10, and Range of Integers from 1 to 10 exclusive (the set {1, 2, 3, ..., 9}), is written 1...10.
A type can be a range base type only if it supports order comparisons. For instance, Integer, Real, and String types support order comparisons and so may be range base types however Sets and Arrays don't, so they can't be range base types.