instance method
String#casecmp
(::string other) -> (-1 | 0 | 1)
(untyped) -> (-1 | 0 | 1)?
casecmp(other_string) → -1, 0, 1, or nil
string.c
View on GitHub ↗
static VALUE
rb_str_casecmp(VALUE str1, VALUE str2)
{
VALUE s = rb_check_string_type(str2);
if (NIL_P(s)) {
return Qnil;
}
return str_casecmp(str1, s);
}
Ignoring case, compares self and other_string; returns:
-
-1 if
self.downcaseis smaller thanother_string.downcase. -
0 if the two are equal.
-
1 if
self.downcaseis larger thanother_string.downcase. -
nilif the two are incomparable.
See Case Mapping.
Examples:
Example
'foo'.casecmp('goo') # => -1 'goo'.casecmp('foo') # => 1 'foo'.casecmp('food') # => -1 'food'.casecmp('foo') # => 1 'FOO'.casecmp('foo') # => 0 'foo'.casecmp('FOO') # => 0 'foo'.casecmp(1) # => nil
Related: see Comparing.