Skip to content
instance method

Module#<=>

(untyped other) -> ::Integer?
self <=> other → -1, 0, 1, or nil

Compares self and other.

Returns:

  • -1, if self includes other, if or self is a subclass of other.

  • 0, if self and other are the same.

  • 1, if other includes self, or if other is a subclass of self.

  • nil, if none of the above is true.

Examples:

Example
# Class Array includes module Enumerable.
         Array <=> Enumerable # => -1
    Enumerable <=> Enumerable # =>  0
    Enumerable <=> Array      # =>  1
# Class File is a subclass of class IO.
          File <=> IO         # => -1
          File <=> File       # =>  0
            IO <=> File       # =>  1
# Class File has no relationship to class String.
          File <=> String     # => nil
See also #<= #== #< #=== also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0