Ruby 4.0 リファレンスマニュアル

instance method Numeric#<=>

self <=> other -> -1 | 0 | 1 | nil[permalink][rdoc][edit]
(Numeric other) → Integer

selfother と比較し、selfother より大きければ 1 を、等しければ 0 を、小さければ -1 を返します。比較できないときは nil を返します。

Numeric のサブクラスは必要に応じてこのメソッドを適切に再定義しなければなりません。

Numeric オブジェクトを左項とする比較演算子 <=> はこのメソッドの呼び出しになります。

[PARAM] other:
比較対象
p 1 <=> 0   # => 1
p 1 <=> 1   # => 0
p 1 <=> 2   # => -1
p 1 <=> "0" # => nil