Skip to content
instance method

Object#<=>

(untyped other) -> 0?
self <=> other → 0 or nil

Compares self and other.

Returns:

  • 0, if self and other are the same object, or if self == other.

  • nil, otherwise.

Examples:

Example
o = Object.new
o <=> o     # => 0
o <=> o.dup # => nil

A class that includes module Comparable should override this method by defining an instance method that:

  • Take one argument, other.

  • Returns:

    • -1, if self is less than other.

    • 0, if self is equal to other.

    • 1, if self is greater than other.

    • nil, if the two values are incommensurate.

See also #!~ #=== .yaml_tag #define_singleton_method also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0