From: apeiros on

Am 17.04.2010 um 12:48 schrieb apeiros:

> Am 12.04.2010 um 17:51 schrieb Intransition:
>> Do you run into the issue of sorting [1,2,3, [:a,:b,:c]] where by an
>> error is raised when it tries, 1 <=> [:a,:b,:c] ?
>
> How does recursively sorting [1,2,3, [:a,:b,:c]] make any sense? That's just as broken as trying to sort [:a, "b", 3, Time.now] - those values are not comparable and sort will raise.
> I can see sorting e.g. [[2,5,4],[3,2,1]] recursively making sense, though, the result being [[1,2,3],[2,4,5]]. But the above should just raise, anything else makes IMO no sense.

Addendum: of course I'm talking about sort without a block. If you supply a block to sort, it'd be entirely possible:
[3,1,2, ["b","c","a"]].recursively.sort { |a,b| a.class == b.class ? a <=> b : a.class.to_s <=> b.class.to_s } # => [["a","b","c"],1,2,3]

Regards
Stefan
First  |  Prev  | 
Pages: 1 2 3 4 5 6
Prev: what is the meaning of \A and \Z
Next: win32ole question