Joe Johnson
10/22/2003 2:09:00 AM
Tim Hunter wrote:
> On Tue, 21 Oct 2003 16:58:49 -0700, Joe Johnson wrote:
>
>
>>Tim Hunter wrote:
>>
>>>On Tue, 21 Oct 2003 17:47:20 -0500, Lyle Johnson wrote:
>>>
>>>
>>>
>>>>If you instead type the expression:
>>>>
>>>> x == 0
>>>>
>>>>into irb, I would have expected irb to respond:
>>>>
>>>> => false
>>>>
>>>>but it instead responds:
>>>>
>>>> => nil
>>>>
>>>>and this admittedly surprised me :(
>>>
>>>
>>>IIRC, in 1.8.0, <=> returns nil when the operands are in different
>>>classes. false is reserved for the case when both operands are in the
>>>same class but have different values.
>>>
>>>
>>
>>Hmm.... I don't get nil when I compare different types. Any thoughts?
>>
>>irb(main):001:0> 1==1
>>=> true
>>irb(main):002:0> 1=="1"
>>=> false
>>irb(main):003:0> 1=="3"
>>=> false
>>irb(main):004:0> "3"==3
>>=> false
>>irb(main):005:0> x="3"
>>=> "3"
>>irb(main):006:0> x==3
>>=> false
>
>
>
> I think it works for me...
>
> [tim:~/rb]$ irb
> irb(main):001:0> 1==1
> => true
> irb(main):002:0> 1=="1"
> => nil
> irb(main):003:0> 1=="3"
> => nil
> irb(main):004:0> "3"==3
> => nil
> irb(main):005:0> x="3"
> => "3"
> irb(main):006:0> x==3
> => nil
> irb(main):007:0> VERSION
> => "1.8.0"
> irb(main):008:0>
>
> [tim:~/rb]$ irb -v
> irb 0.9(02/07/03)
> [tim:~/rb]$ ruby -v
> ruby 1.8.0 (2003-08-04) [i686-linux]
> [tim:~/rb]$
Oh.. I see, my have version 1.6.8. I bet
the behavior has changed. Has this been documented somewhere?