class SocketEndpoint
This class doesn't exert ownership over the specified socket, wraps a native ::IO.
Definitions
def initialize(socket, **options)
Initialize a new socket endpoint.
Signature
-
parameter
socketSocket The socket to wrap.
-
parameter
optionsHash Additional options to pass to the parent class.
Implementation
def initialize(socket, **options)
super(**options)
@socket = socket
end
def to_s
Get a string representation of the socket endpoint.
Signature
-
returns
String A string representation showing the socket.
Implementation
def to_s
"socket:#{@socket}"
end
def inspect
Get a detailed string representation of the socket endpoint.
Signature
-
returns
String A detailed string representation including the socket.
Implementation
def inspect
"\#<#{self.class} #{@socket.inspect}>"
end
attr :socket
Signature
-
attribute
Socket The wrapped socket.
def bind(&block)
Bind using the wrapped socket.
Signature
-
yields
{|socket| ...} If a block is given, yields the socket.
-
parameter
socketSocket The socket.
-
parameter
-
returns
Socket The socket.
Implementation
def bind(&block)
if block_given?
yield @socket
else
return @socket
end
end
def connect(&block)
Connect using the wrapped socket.
Signature
-
yields
{|socket| ...} If a block is given, yields the socket.
-
parameter
socketSocket The socket.
-
parameter
-
returns
Socket The socket.
Implementation
def connect(&block)
if block_given?
yield @socket
else
return @socket
end
end