diff options
author | Shugo Maeda <shugo@ruby-lang.org> | 2019-04-22 17:15:49 +0900 |
---|---|---|
committer | Shugo Maeda <shugo@ruby-lang.org> | 2019-04-22 17:15:49 +0900 |
commit | f005ccc771574e8e4e17b7a35c19b352e0b7dc73 (patch) | |
tree | b424ff42e646560ff15e4273912e038d0dfdd1e0 | |
parent | 6013e41a7bb1d6909e0538ccb885b477bd080163 (diff) |
Clarify requirements of <=>
A return value of <=> is automatically converted to -1, 0, or 1, so
other values can be returned. [Misc #15630]
-rw-r--r-- | compar.c | 13 |
1 files changed, 7 insertions, 6 deletions
@@ -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 |