From 2d69facd2093ed9e51a6e10f8234c4fda07ef6f1 Mon Sep 17 00:00:00 2001 From: Burdette Lamar Date: Sun, 21 Dec 2025 13:05:38 -0600 Subject: [PATCH] [DOC] Tweaks for Object#<=> --- object.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/object.c b/object.c index 93c8a483cf..aaa3326ebf 100644 --- a/object.c +++ b/object.c @@ -1766,21 +1766,33 @@ rb_obj_not_match(VALUE obj1, VALUE obj2) /* * call-seq: - * obj <=> other -> 0 or nil + * self <=> other -> 0 or nil * - * Returns 0 if +obj+ and +other+ are the same object - * or obj == other, otherwise nil. + * Compares +self+ and +other+. * - * The #<=> is used by various methods to compare objects, for example - * Enumerable#sort, Enumerable#max etc. + * Returns: * - * Your implementation of #<=> should return one of the following values: -1, 0, - * 1 or nil. -1 means self is smaller than other. 0 means self is equal to other. - * 1 means self is bigger than other. Nil means the two values could not be - * compared. + * - +0+, if +self+ and +other+ are the same object, + * or if self == other. + * - +nil+, otherwise. + * + * Examples: + * + * o = Object.new + * o <=> o # => 0 + * o <=> o.dup # => nil + * + * A class that includes module Comparable + * should override this method by defining an instance method that: + * + * - Take one argument, +other+. + * - Returns: + * + * - +-1+, if +self+ is less than +other+. + * - +0+, if +self+ is equal to +other+. + * - +1+, if +self+ is greater than +other+. + * - +nil+, if the two values are incommensurate. * - * When you define #<=>, you can include Comparable to gain the - * methods #<=, #<, #==, #>=, #> and #between?. */ static VALUE rb_obj_cmp(VALUE obj1, VALUE obj2)