Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Symbol#<=>
(::Symbol object) -> (-1 | 0 | 1)
(untyped) -> (-1 | 0 | 1)?
self <=> other → -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));
}
Compares self and other, using String#<=>.
Returns:
-
self.to_s <=> other.to_s, ifotheris 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#<=>.