From: matu Date: 2008-07-30T06:19:28+09:00 Subject: the old sorting ip addresses problem i am sure there has to be some ruby way of doing this in a really simple way... i came up with this, but i am sure there is some other way that is much cleaner. >> a = ["5.100.200.50", "10.150.50.1", "10.150.50.2", "10.150.51.1", "19.18.16.15", "192.168.0.1"] => ["5.100.200.50", "10.150.50.1", "10.150.50.2", "10.150.51.1", "19.18.16.15", "192.168.0.1"] >> a.sort {|a1, a2| y = [a1, a2].map {|addr| x = 0; addr.split('.').reverse.each_with_index {|n, i| x = x + n.to_i * (256 ** (i))}; x}; y.last <=> y.first} => ["192.168.0.1", "19.18.16.15", "10.150.51.1", "10.150.50.2", "10.150.50.1", "5.100.200.50"] >>