Yes! Thats exactly what I was missing.  Why would someone write <=> for nil?

On Fri, May 8, 2009 at 4:23 PM, Adam Gardner <adam.oddfellow / gmail.com> wrote:
> RubyTalk / gmail.com wrote:
>>>> nil==0
>> => false
>>>> class NilClass
>>>> include Comparable
>>>> def <=>(other)
>>>> 
>>>> end
>>>> end
>> => nil
>>>> [1,nil,2].sort
>> ArgumentError: comparison of Fixnum with nil failed
>> from (irb):11:in `sort'
>> from (irb):11
>>>> p nil > 2
>> false
>> => nil
>>>> p nil > -1
>> false
>> => nil
>>>> p nil == 0
>> true
>> => nil
>>
>>
>>
>> What I am missing here?
>
> Probably this:
>
> irb(main):003:0> class NilClass
> irb(main):004:1> def <=>(other)
> irb(main):005:2> 0
> irb(main):006:2> end
> irb(main):007:1> end
> => nil
> irb(main):008:0> nil <=> 1
> => 0
> irb(main):009:0> 1 <=> nil
> => nil
> irb(main):010:0>
> --
> Posted via http://www.ruby-forum.com/.
>
>