My understanding is that you can only overload existing operators like ==, !, === but not define custom ones. Operator overloading should be handled carefully in any case. I think it is good thing that custom operators are not allowed / possible. > --- Ursprgliche Nachricht --- > Von: Pavel Smerk <smerk / fi.muni.cz> > An: ruby-talk / ruby-lang.org (ruby-talk ML) > Betreff: Re: "str1" == "STR1" case insensitive > Datum: Wed, 22 Mar 2006 22:23:53 +0900 > > Peter Ertl wrote: > > class String > > def eq(arg) > > self.casecmp(arg ) == 0 > > end > > end > > > > puts "Test".eq("test") > > > >>true > > And how can I define eq as an binary operator on String-s allowing me to > write "Test" eq "test"? (And if this is possible, how can set a priority > for such operator?) > > P. > > >>--- Ursprgliche Nachricht --- > >>On 3/21/06, Shea Martin <null / void.0> wrote: > >> > >>>For doing case insensitive comparisons, I have been using > >>> > >>>if str1.casecmp(str2)==0 > >>> puts 'equal' > >>>else > >>> puts 'not equal' > >>>end > >>> > >>>Is their a way to do this with simpler syntax? > >> > >>I find String#downcase convenient for these sorts of comparisons: > >> > >> if str1.downcase == str2.downcase > >> puts 'equal' > >> else > >> puts 'not equal' > >> end > >> > >>Jacob Fugal > >> > > > > > > >