From: Gavin Sinclair Date: 2003-10-22T23:47:22+09:00 Subject: Re: [Q] Array not Comparable? On Thursday, October 23, 2003, 12:40:50 AM, ts wrote: >>>>>> "G" == Gavin Sinclair writes: G>> A. "Arrays are not comparable in general." G>> B. Array implements <=>. G>> Seems like a contradiction to me. > Well, if you look at the classes which include Comparable you'll see that > #<=> return (-1, 0, 1) when the 2 objects are in the same class (this is > simplified, see for example String#<=>) > This is not the case for Array > svg% ruby -e 'p ([1, "a"] <=> [1, 2])' > nil > svg% > You have 2 arrays, but ruby can't compare these objects So: class Array include Comparable end [1, 3] > [1, 2] # true [1, "a"] > [1, 2] # ArgumentError: comparison of Array with Array failed Seems logical to me. Gavin