Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

String#casecmp?

string.casecmp?(other_string) → true, false, or nil

Returns true if self and other_string are equal after Unicode case folding, otherwise false:

Example
'foo'.casecmp?('foo') # => true
'foo'.casecmp?('food') # => false
'food'.casecmp?('foo') # => true
'FOO'.casecmp?('foo') # => true
'foo'.casecmp?('FOO') # => true

Returns nil if the two values are incomparable:

Example
'foo'.casecmp?(1) # => nil
See also #casecmp #center #capitalize! #chars also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1