Range

A Range represents an interval—a set of values with a
beginning and an end. Ranges may be constructed using the
s..e and
s...e literals, or with ::new. Ranges constructed using
.. run from the beginning to the end inclusively. Those
created using ... exclude the end value. When used as an
iterator, ranges return each value in the sequence.

Ranges can be constructed using any objects that can be compared using the
<=> operator. Methods that treat the range as a sequence
(#each and methods inherited from Enumerable)
expect the begin object to implement a succ method to return
the next object in sequence. The step and include? methods require the
begin object to implement succ or to be numeric.

In the Xs class below both <=> and
succ are implemented so Xs can be used to
construct ranges. Note that the Comparable
module is included so the == method is defined in terms of
<=>.