Or, based on Carlos' optimisation (and I use the term very loosely in
the context of golfing):
hex_ip.scan(/../).map{$&.hex}*"."
Saves another two characters... and looks horribly perlish.
You've broken it
"c0a80167".scan(/../).map{$&.hex}*"."
=> "103.103.103.103"
$& holds the last match of the regex, not the current iteration of map.
<digress>
On that note, it's a bit of a shame that $_ doesn't work more like it
does in perl. It would be very useful when golfing to have a variable
that holds the parameters passed to a block without having to explicitly
include an argument list to receive them.
(Although, I suppose that variable would have to be an array to receive
multiple arguments, so the advantage would be lost because of the extra
bytes needed to get values out of that array.)
Oh well. Ruby is still good for golfing, it's winning a good few of the
challenges on codegolf.com.
</digress>
--
Regards,
Carl Drinkwater | 29degrees Ltd
29degrees.co.uk - Bespoke Web Application Development.
codegolf.com - Can you craft the smallest code?