From: Tanaka Akira Date: 2003-02-21T12:16:40+09:00 Subject: [ruby-dev:19628] Re: compare between String and Exception In article <1045773281.614432.25616.nullmailer@picachu.netlab.jp>, matz@ruby-lang.org (Yukihiro Matsumoto) writes: > * aがstringで > * bがstringでないなら > * to_strを定義していなければnil > * <=>が定義されていなければnil > * でなければ 0-(b<=>a) ふむ。b<=>a が nil を返したら nil を返すというのが抜けてる気がしますが、 あとはいいと思います。 ただ、実装がそうなっているかというとそうでもないようで。 % ruby -e 'class C def to_str end def <=>(other) 1 end end p "a" <=> C.new' 1 というのは仕様では -1 になると思いますし、 % ruby -e 'class C def to_str end def <=>(other) nil end end p "a" <=> C.new' -e:8:in `-': wrong number of arguments(4 for 1) (ArgumentError) from -e:8:in `<=>' from -e:8 というエラーは変です。 -- [田中 哲][たなか あきら][Tanaka Akira]