From: Manuel Kasten Date: 2005-11-10T16:57:13+09:00 Subject: Re: Question regarding <=> operator and Comparable Mixin Yukihiro Matsumoto schrieb: > Hi, > > In message "Re: Question regarding <=> operator and Comparable Mixin" > on Thu, 10 Nov 2005 02:27:12 +0900, Manuel Kasten writes: > > |But if I return nil (just like Integer <=> String) <= is fine [line > |009], but == behaves differently from what I expected. Why doesn't [line > |11] return false like [line 10] does? I thought == is supposed to return > |true or false, nothing else? > > "nil" denotes underlying assumption (<=> to return an integer value) > is not met. Ruby sometimes use nil as a small error indicator. > > matz. Hi, then why doesn't [line10] return nil? a <=> b is nil [6], so is c <=> d [7]. a == b returns false [10], while c == d returns nil [11]. I expected both to return nil or both to return false. Thanks for your help, Manuel Kasten irb(main):002:0> a = 5 => 5 irb(main):003:0> b = "Hallo" => "Hallo" irb(main):004:0> c = Modnum.new(3,7) => # irb(main):005:0> d = Modnum.new(3,9) => # irb(main):006:0> a <=> b => nil irb(main):007:0> c <=> d => nil irb(main):010:0> a == b => false irb(main):011:0> c == d => nil