Yossef Mendelssohn
3/28/2009 2:32:00 AM
On Mar 27, 9:18=A0pm, Aaron Vegh <aa...@vegh.ca> wrote:
> When the index numbers are float or strings, they sort like this. But I
> want "1.10" to be the last number. Any idea how to put these guys in the
> right order?
$ irb
>> nums =3D ['1.1', '1.2', '1.10', '1.9']
=3D> ["1.1", "1.2", "1.10", "1.9"]
>> nums.sort
=3D> ["1.1", "1.10", "1.2", "1.9"]
>> nums.collect { |n| n.split('.').collect { |i|
i.to_i } }.sort.collect { |n| n.join('.') }
=3D> ["1.1", "1.2", "1.9", "1.10"]
--
-yossef