From: Daniel Berger Date: 2006-12-02T06:03:59+09:00 Subject: Re: cidr.rb: port of Perl's Net::CIDR v0.11 available Jos Backus wrote: > On Sat, Dec 02, 2006 at 04:54:49AM +0900, Daniel Berger wrote: >> Jos Backus wrote: >> Seems to work. Mind if I include with the next release of net-ping >> (with acknowledgements, of course). > > Of course, thanks Daniel. Great, thanks. >> The only tweak I would make are to have it return true or false, instead >> of 1 or nil. > > Good idea. Now, the Perl Net::Ping library returns duration: > > ($ret, $duration, $ip) = $p->ping($host, $timeout); > > In array context, the elapsed time as well as the string form of the ip > the host resolved to are also returned. > > What would be the best way to add that to the Ruby version? Obviously one > would want all Net::Ping classes to support this. I have a local utility that > uses this information, which is why I need it. > > Cheers, Hm, I'll have to think about the API. I suppose the most simple approach is to just add accessors for duration and ip_address (with a 'nil' value by default). In practice, then, your code would look like this: if p.ping? puts p.ip_address puts p.duration end How does that look? Regards, Dan