From: Carlos Date: 2006-12-06T19:17:06+09:00 Subject: Re: GOLF: hex string to dotted quad Max Muermann wrote: > On 12/6/06, Martin DeMello wrote: > >> irb(main):021:0> hex_ip = "c0a80167" >> => "c0a80167" >> irb(main):022:0> ip = hex_ip.scan(/../).map {|i| i.to_i(16)}.join(".") >> => "192.168.1.103" > > > hex_ip.gsub(/../) {|s| "#{s.hex}."}[0..-2] > > The deletion of the trailing '.' is so ugly... but it's a leetle bit > shorter ;) The best so far :). Further refining: hex_ip.gsub(/../) {"#{$&.hex}."}.chop --