Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Symbol#<=>

symbol <=> object → -1, 0, +1, or nil

If object is a symbol, returns the equivalent of symbol.to_s <=> object.to_s:

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

Otherwise, returns nil:

Example
:foo <=> 'bar' # => nil

Related: String#<=>.

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