Skip to content
instance method

Symbol#<=>

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

Compares self and other, using String#<=>.

Returns:

  • self.to_s <=> other.to_s, if other is a symbol.

  • nil, otherwise.

Examples:

Example
:bar <=> :foo  # => -1
:foo <=> :foo  # => 0
:foo <=> :bar  # => 1
:foo <=> 'bar' # => nil

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

Related: String#<=>.

See also .json_create #== .all_symbols #=== also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0