Method: String#casecmp

Defined in:
string.c

#casecmp(other_string) ⇒ -1, ...

Compares self.downcase and other_string.downcase; returns:

  • -1 if other_string.downcase is larger.

  • 0 if the two are equal.

  • 1 if other_string.downcase is smaller.

  • nil if the two are incomparable.

Examples:

'foo'.casecmp('foo') # => 0
'foo'.casecmp('food') # => -1
'food'.casecmp('foo') # => 1
'FOO'.casecmp('foo') # => 0
'foo'.casecmp('FOO') # => 0
'foo'.casecmp(1) # => nil

See Case Mapping.

Related: String#casecmp?.

Returns:

  • (-1, 0, 1, nil)


4252
4253
4254
4255
4256
4257
4258
4259
4260
# File 'string.c', line 4252

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);
}