0051 String_comparison

Case insensitive comparison

casecmp? compares 2 strings without taking case into account. When it comes to unicode characters, there are a few subtleties! With a non-compatible type, the method returns nil rather than an exception.

0051-string_comparison_1.png

There’s also the casecmp method for comparing 2 strings without taking case into account, but it returns -1, 0 or 1 (or nil if incompatible) which can be used to sort, for example.

0051-string_comparison_2.png

Links to Ruby documentation for casecmp? and casecmp.