Ruby 2.5.0 リファレンスマニュアル > ライブラリ一覧 > 組み込みライブラリ > Integerクラス > <=>

instance method Integer#<=>

self <=> other -> -1 | 0 | 1 | nil[permalink][rdoc]

self と other を比較して、self が大きい時に1、等しい時に 0、小さい時に-1、比較できない時に nil を返します。

[PARAM] other:
比較対象の数値
[RETURN]
-1 か 0 か 1 か nil のいずれか

1 <=> 2  # => -1
1 <=> 1  # => 0
2 <=> 1  # => 1
2 <=> '' # => nil