Project

General

Profile

Actions

Misc #12835

closed

RDoc comment of String#casecmp

Misc #12835: RDoc comment of String#casecmp

Added by dogatana (Toshihiko Ichida) about 9 years ago. Updated over 8 years ago.

Status:
Closed
Assignee:
-
[ruby-dev:49835]

Description

String#casecmp dose not return nil but raise TypError for incomparable argument.

So

 * str.casecmp(other_str) -> -1, 0, +1 or nil 

should be like

 * str.casecmp(other_str) -> -1, 0, +1 

or

 * str.casecmp(other_str) -> -1, 0, +1 or raise TypeError if other_str is not comparable 

Here is a example.

irb(main):001:0> "a" <=> 1 => nil irb(main):002:0> "a".casecmp(1) TypeError: no implicit conversion of Fixnum into String 

Japanese Reference Manual has same issue.

Updated by znz (Kazuhiro NISHIYAMA) about 9 years ago Actions #1 [ruby-dev:49837]

I created pull request for Japanese Reference Manual.

Updated by stomar (Marcus Stollsteimer) over 8 years ago Actions #2 [ruby-dev:50014]

Note that String#casecmp can return nil:

"\u{e4 f6 fc}".encode("ISO-8859-1").casecmp("\u{c4 d6 dc}") #=> nil 

The relevant lines in the source code (in string.c):

static VALUE rb_str_casecmp(VALUE str1, VALUE str2) { /* ... */ enc = rb_enc_compatible(str1, str2); if (!enc) { return Qnil; } /* ... */ } 

Updated by stomar (Marcus Stollsteimer) over 8 years ago Actions #3 [ruby-dev:50015]

I tried to clarify this in the rdoc with r57886.

Updated by stomar (Marcus Stollsteimer) over 8 years ago Actions #4 [ruby-dev:50066]

  • Status changed from Open to Closed

Closing since the rdoc matches the actual behavior. Additionally I opened a new issue because raising TypeError seems to be inconsistent with other comparison methods, see #13312.

Actions

Also available in: PDF Atom