End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Symbol#casecmp
casecmp(other_symbol) → -1, 0, 1, or nil
string.c
View on GitHub ↗
static VALUE
sym_casecmp(VALUE sym, VALUE other)
{
if (!SYMBOL_P(other)) {
return Qnil;
}
return str_casecmp(rb_sym2str(sym), rb_sym2str(other));
}
Case-insensitive version of Symbol#<=>:
Example
:aBcDeF.casecmp(:abcde) # => 1 :aBcDeF.casecmp(:abcdef) # => 0 :aBcDeF.casecmp(:abcdefg) # => -1 :abcdef.casecmp(:ABCDEF) # => 0
Returns nil if the two symbols have incompatible encodings, or if other_symbol is not a symbol:
Example
sym = "\u{e4 f6 fc}".encode("ISO-8859-1").to_sym other_sym = :"\u{c4 d6 dc}" sym.casecmp(other_sym) # => nil :foo.casecmp(2) # => nil
Currently, case-insensitivity only works on characters A-Z/a-z, not all of Unicode. This is different from Symbol#casecmp?.
Related: Symbol#casecmp?.