From: nobu.nakada@... Date: 2001-04-16T16:44:25+09:00 Subject: [ruby-dev:12967] Re: case-insensitive String comparison なかだです。 At Mon, 16 Apr 2001 01:05:59 +0900, matz@zetabits.com (Yukihiro Matsumoto) wrote: > | それは String#insensitive というメソッドだけに対して、それと > |も case insensitive な String というもの自体ですか? > > 後者です。やはり文字列に導入するにしては強すぎる属性だと思い > ます。単なる感覚ですが。 それも納得なんですが、文字ケースを無視する比較メソッドを追加 したとしても、そのままでは Comparable の恩恵が受けられないから "B".casecmp("a") < 0 なんてしないといけなくなるあたりがちょっと うれしくないなと。 まぁどうしてもそういう使い方をしたければ自分でそういうサブク ラスを作れというのもありでしょうが。 class String def insensitive; Insensitive.new(self); end def sensitive; self; end class Insensitive < self alias <=> casecmp def insensitive; self; end def sensitive; String.new(self); end end end それと比較メソッドを追加する場合、名前はどういうのがいいでしょ う。上に書いたのは安直に strcasecmp から str を取りましたが。 -- --- 僕の前にBugはない。 --- 僕の後ろにBugはできる。 中田 伸悦