Last active
December 14, 2015 02:49
-
-
Save apeiros/5016976 to your computer and use it in GitHub Desktop.
Better docs for Object#<=>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= Object#<=> | |
(from ruby site) | |
------------------------------------------------------------------------------ | |
obj <=> other -> 0 or nil | |
------------------------------------------------------------------------------ | |
Returns 0 if obj === other, otherwise nil. | |
The <=> is used by various methods to compare Objects, for example | |
Enumerable#sort, Enumerable#max etc. | |
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. | |
When you defined <=>, you can include Comparable to gain the methods <=, <, | |
==, >=, > and between?. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The first commit is the docs as of ruby-1.9.3-p385