Skip to content

Commit 2d69fac

Browse files
[DOC] Tweaks for Object#<=>
1 parent d0ec60d commit 2d69fac

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

object.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,21 +1766,33 @@ rb_obj_not_match(VALUE obj1, VALUE obj2)
17661766

17671767
/*
17681768
* call-seq:
1769-
* obj <=> other -> 0 or nil
1769+
* self <=> other -> 0 or nil
17701770
*
1771-
* Returns 0 if +obj+ and +other+ are the same object
1772-
* or <code>obj == other</code>, otherwise nil.
1771+
* Compares +self+ and +other+.
1772+
*
1773+
* Returns:
1774+
*
1775+
* - +0+, if +self+ and +other+ are the same object,
1776+
* or if <tt>self == other</tt>.
1777+
* - +nil+, otherwise.
1778+
*
1779+
* Examples:
1780+
*
1781+
* o = Object.new
1782+
* o <=> o # => 0
1783+
* o <=> o.dup # => nil
1784+
*
1785+
* A class that includes module Comparable
1786+
* should override this method by defining an instance method that:
17731787
*
1774-
* The #<=> is used by various methods to compare objects, for example
1775-
* Enumerable#sort, Enumerable#max etc.
1788+
* - Take one argument, +other+.
1789+
* - Returns:
17761790
*
1777-
* Your implementation of #<=> should return one of the following values: -1, 0,
1778-
* 1 or nil. -1 means self is smaller than other. 0 means self is equal to other.
1779-
* 1 means self is bigger than other. Nil means the two values could not be
1780-
* compared.
1791+
* - +-1+, if +self+ is less than +other+.
1792+
* - +0+, if +self+ is equal to +other+.
1793+
* - +1+, if +self+ is greater than +other+.
1794+
* - +nil+, if the two values are incommensurate.
17811795
*
1782-
* When you define #<=>, you can include Comparable to gain the
1783-
* methods #<=, #<, #==, #>=, #> and #between?.
17841796
*/
17851797
static VALUE
17861798
rb_obj_cmp(VALUE obj1, VALUE obj2)

0 commit comments

Comments
 (0)