--- Paul Brannan <pbrannan / atdesk.com> wrote:
> I was playing with <=> recently, and I noticed that the following:
> 
>   class Foo
>     def ==(other)
>       raise "uh oh"
>     end
>   end
>   p Foo.new == 42
> 
> prints (on Ruby 1.6 and 1.7):
> 
>   -:3:in `==': uh oh (RuntimeError)
>           from -:6
> 
> However:
> 
>   class Foo
>     include Comparable
>     def <=>(other)
>       raise "uh oh"
>     end
>   end
>   p Foo.new == 42
> 
> prints:
> 
>   false
> 
> While this makes sense (if <=> raises an exception, then the two
> values
> probably weren't equal), it is inconsistent.  If an exception gets
> propogated in one case, it should be propogated in another case.  I
> think it would be preferable for <=> to always propogate the
> exception,
> since some exceptions (ArgumentError, NameError, etc.) often
> indicate
> bugs, and catching them prevents unit tests from catching potential
> problems.
> 
> Any thoughts?


This seems correct to me; you're not calling <=> in the second code
snippet.

Is this what you meant?

c:\tmp>cat tmp.rb
cat tmp.rb

  class Foo
    include Comparable
    def <=>(other)
      raise "uh oh"
    end
  end
  p Foo.new <=> 42


c:\tmp>ruby tmp.rb
ruby tmp.rb
tmp.rb:5:in `<=>': uh oh (RuntimeError)
	from tmp.rb:8





=====
--
Yahoo IM: michael_s_campbell

__________________________________________________
Do You Yahoo!?
LAUNCH - Your Yahoo! Music Experience
http://launch.yahoo.com