Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Numeric#<=>

(::Numeric other) -> ::Integer
self <=> other → zero or nil

Compares self and other.

Returns:

  • Zero, if self is the same as other.

  • nil, otherwise.

Class Numeric includes module Comparable, each of whose methods uses Numeric#<=> for comparison.

No subclass in the Ruby Core or Standard Library uses this implementation.

See also #-@ #abs #+@ #abs2 also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0