Tanaka Akira wrote:
...
> How about this like Python?
> 
> [1,"1"].sort_by {|v| [v.class.name, v] }
> 
> However Python behaves bit differently on numbers.

I hope so...

   p [1, "1", 1.5, 2].sort_by {|v| [v.class.name, v] }

     # ==> [1, 2, 1.5, "1"]

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)