From: matu Date: 2008-07-30T06:34:26+09:00 Subject: Re: the old sorting ip addresses problem Martin DeMello wrote: > a.sort_by {|x| x.split(/\./).map {|i| i.to_i}}.reverse > > => ["192.168.0.1", "19.18.16.15", "10.150.51.1", "10.150.50.2", > "10.150.50.1", "5.100.200.50"] > > This relies on the fact that ruby has built-in array sorting, where > it'll sort by the first element, then break ties on the second > element, and so on, and a built-in sort_by function, that transforms a > collection according to the block given, and sorts by the transformed > values. > thanks. this is much cleaner.