mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Clarify requirements of <=>
A return value of <=> is automatically converted to -1, 0, or 1, so other values can be returned. [Misc #15630]
This commit is contained in:
parent
6013e41a7b
commit
f005ccc771
1 changed files with 7 additions and 6 deletions
13
compar.c
13
compar.c
|
@ -95,7 +95,7 @@ cmpint(VALUE x, VALUE y)
|
|||
* obj > other -> true or false
|
||||
*
|
||||
* Compares two objects based on the receiver's <code><=></code>
|
||||
* method, returning true if it returns 1.
|
||||
* method, returning true if it returns a value greater than 0.
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
|
@ -110,7 +110,7 @@ cmp_gt(VALUE x, VALUE y)
|
|||
* obj >= other -> true or false
|
||||
*
|
||||
* Compares two objects based on the receiver's <code><=></code>
|
||||
* method, returning true if it returns 0 or 1.
|
||||
* method, returning true if it returns a value greater than or equal to 0.
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
|
@ -125,7 +125,7 @@ cmp_ge(VALUE x, VALUE y)
|
|||
* obj < other -> true or false
|
||||
*
|
||||
* Compares two objects based on the receiver's <code><=></code>
|
||||
* method, returning true if it returns -1.
|
||||
* method, returning true if it returns a value less than 0.
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
|
@ -140,7 +140,7 @@ cmp_lt(VALUE x, VALUE y)
|
|||
* obj <= other -> true or false
|
||||
*
|
||||
* Compares two objects based on the receiver's <code><=></code>
|
||||
* method, returning true if it returns -1 or 0.
|
||||
* method, returning true if it returns a value less than or equal to 0.
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
|
@ -209,8 +209,9 @@ cmp_clamp(VALUE x, VALUE min, VALUE max)
|
|||
/*
|
||||
* The Comparable mixin is used by classes whose objects may be
|
||||
* ordered. The class must define the <code><=></code> operator,
|
||||
* which compares the receiver against another object, returning -1,
|
||||
* 0, or +1 depending on whether the receiver is less than, equal to,
|
||||
* which compares the receiver against another object, returning
|
||||
* a value less than 0, 0, or a value greater than 0, depending on
|
||||
* whether the receiver is less than, equal to,
|
||||
* or greater than the other object. If the other object is not
|
||||
* comparable then the <code><=></code> operator should return +nil+.
|
||||
* Comparable uses <code><=></code> to implement the conventional
|
||||
|
|
Loading…
Reference in a new issue