Skip to content

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) → true, false, or nil

Returns true if sym and other_symbol are equal after Unicode case folding, false if they are not equal:

Example
:aBcDeF.casecmp?(:abcde)                  # => false
:aBcDeF.casecmp?(:abcdef)                 # => true
:aBcDeF.casecmp?(:abcdefg)                # => false
:abcdef.casecmp?(:ABCDEF)                 # => true
:"\u{e4 f6 fc}".casecmp?(:"\u{c4 d6 dc}") #=> true

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

See Case Mapping.

Related: Symbol#casecmp.

See also #casecmp #downcase #capitalize #empty? also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0