Ruby Newbie homepage Ruby Newbie homepage

How to use

Quick guide

Official content
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
Related: String#casecmp?.
 
               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);
}
            

Was this page useful?