Warren Brown
10/22/2003 3:52:00 PM
Guy,
> svg% ruby -e 'p ([1, "a"] <=> [1, 2])'
> nil
> svg%
I see your point, but:
%ruby -e 'p [[1],[2]].sort'
[[1], [2]]
%ruby -e 'p [[1],["a"]].sort'
-e:1:in `sort': comparison of Array with Array failed (ArgumentError)
from -e:1
So why have Array#sort allow comparisons where possible (throwing an
error where it is not), but not allow comparison operators to do the
same?
irb(main):001:0> class Array
irb(main):002:1> include Comparable
irb(main):003:1> end
=> Array
irb(main):004:0> [1] < [2]
=> true
irb(main):005:0> [1] < ['a']
ArgumentError: comparison of Array with Array failed
from (irb):5:in `<'
from (irb):5
This seems more consistent to me. Anyone else?
- Warren Brown