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
string.c
View on GitHub ↗
static VALUE
sym_cmp(VALUE sym, VALUE other)
{
if (!SYMBOL_P(other)) {
return Qnil;
}
return rb_str_cmp_m(rb_sym2str(sym), rb_sym2str(other));
}
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#<=>.