[ruby-dev:50014] [Ruby trunk Misc#12835] RDoc comment of String#casecmp

From: sto.mar@...
Date: 2017-03-11 21:46:29 UTC
List: ruby-dev #50014
Issue #12835 has been updated by Marcus Stollsteimer.


Note that String#casecmp _can_ return `nil`:

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

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

``` c
static VALUE
rb_str_casecmp(VALUE str1, VALUE str2)
{
    /* ... */

    enc = rb_enc_compatible(str1, str2);
    if (!enc) {
        return Qnil;
    }

    /* ... */
}
```

----------------------------------------
Misc #12835: RDoc comment of String#casecmp
https://bugs.ruby-lang.org/issues/12835#change-63467

* Author: Toshihiko Ichida
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
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.




-- 
https://bugs.ruby-lang.org/

In This Thread

Prev Next