"Joel VanderWerf" <vjoel / PATH.Berkeley.EDU> wrote

> How about using class.name as a fallback, so that Floats and Integers
> get sorted together?
>
>    p [1, "1", 1.5, 2].sort { |x, y|
>      begin
>        x <=> y
>      rescue NoMethodError
>        x.class.name <=> y.class.name
>      end
>    }
>
> Unfortunately, the rescue clause doesn't actually catch the
> NoMethodError. Am I doing something wrong? (ruby-1.7.3)
>
>

   p [1, "1", 1.5, 2].sort { |x, y|
     begin
       x <=> y
     rescue TypeError
#           ^
       x.class.name <=> y.class.name
     end
   }


daz