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

instance method Complex#<=>

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

selfother が共に実数(=虚部がゼロの数)のとき self.real <=> other.real の結果を返します。

そうでないときは nil を返します。

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

[PARAM] other:
比較対象
p Complex(2, 3)  <=> Complex(2, 3) # => nil
p Complex(2, 3)  <=> 1           # => nil
p Complex(2)     <=> 1           # => 1
p Complex(2)     <=> 2           # => 0
p Complex(2)     <=> 3           # => -1