Skip to content

Instantly share code, notes, and snippets.

@apeiros
Last active December 14, 2015 02:49
Show Gist options
  • Save apeiros/5016976 to your computer and use it in GitHub Desktop.
Save apeiros/5016976 to your computer and use it in GitHub Desktop.
Better docs for Object#<=>
= 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?.
@apeiros
Copy link
Author

apeiros commented Feb 22, 2013

The first commit is the docs as of ruby-1.9.3-p385

@zzak
Copy link

zzak commented Feb 23, 2013

@apeiros Thanks! This change landed in r39414

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment