From f005ccc771574e8e4e17b7a35c19b352e0b7dc73 Mon Sep 17 00:00:00 2001 From: Shugo Maeda Date: Mon, 22 Apr 2019 17:15:49 +0900 Subject: Clarify requirements of <=> A return value of <=> is automatically converted to -1, 0, or 1, so other values can be returned. [Misc #15630] --- compar.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/compar.c b/compar.c index dbd4bce96d..3d06592692 100644 --- a/compar.c +++ b/compar.c @@ -95,7 +95,7 @@ cmpint(VALUE x, VALUE y) * obj > other -> true or false * * Compares two objects based on the receiver's <=> - * 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 <=> - * 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 <=> - * 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 <=> - * 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 <=> 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 <=> operator should return +nil+. * Comparable uses <=> to implement the conventional -- cgit v1.2.3