module Comparable(T)
Overview
The Comparable mixin is used by classes whose objects may be ordered.
Including types must provide an <=> method, which compares the receiver against
another object, returning:
- a negative number if
selfis less than the other object - a positive number if
selfis greater than the other object 0ifselfis equal to the other objectnilifselfand the other object are not comparable
Comparable uses <=> to implement the conventional comparison operators
(<, <=, ==, >=, and >). All of these return false when <=>
returns nil.
Note that returning nil is only useful when defining a partial comparable
relationship. One such example is float values: they are generally comparable,
except for NaN. If none of the values of a type are comparable between each
other, Comparable shouldn't be included.
NOTE When nil is returned from <=>, Array#sort and related sorting
methods will perform slightly slower.