The Ping class serves as an abstract base class for all other Ping class types. You should not instantiate this class directly.
The default constructor for the Net::Ping class.
Accepts an optional host
, port
and
timeout
. The port defaults to your echo port, or 7 if that
happens to be undefined. The default timeout is 5 seconds.
The host, although optional in the constructor, must be specified at some point before the #ping method is called, or else an ArgumentError will be raised.
Yields self
in block context.
This class is not meant to be instantiated directly. It is strictly meant as an interface for subclasses.
# File lib/net/ping/ping.rb, line 57 def initialize(host=nil, port=nil, timeout=5) @host = host @port = port || Socket.getservbyname('echo') || 7 @timeout = timeout @exception = nil @warning = nil @duration = nil yield self if block_given? end
The default interface for the #ping method. Each subclass should call super() before continuing with their own implementation in order to ensure that the @exception and @warning instance variables are reset.
If host
is nil here, then it will use the host specified in
the constructor. If the host
is nil and there was no host
specified in the constructor then an ArgumentError is raised.
# File lib/net/ping/ping.rb, line 79 def ping(host = @host) raise ArgumentError, 'no host specified' unless host @exception = nil @warning = nil @duration = nil end