Class: TCPClient::Address
- Inherits:
-
Object
- Object
- TCPClient::Address
- Defined in:
- lib/tcp-client/address.rb
Overview
Note:
The address used by a TCPClient.
Instance Attribute Summary collapse
-
#addrinfo ⇒ Addrinfo
readonly
The address info.
-
#host ⇒ String
(also: #hostname)
readonly
The host name.
-
#port ⇒ Integer
readonly
The port number.
Instance Method Summary collapse
-
#freeze ⇒ Address
Force the address resolution and prevents further modifications of itself.
-
#initialize(addr) ⇒ Address
constructor
Initializes an address.
-
#to_h(&block) ⇒ Hash
Convert
self
to a Hash containing host and port attribute. -
#to_hash ⇒ Hash
Convert
self
to a Hash containing host and port attribute. -
#to_s ⇒ String
Text representation of self as "host:port".
Constructor Details
Instance Attribute Details
#addrinfo ⇒ Addrinfo (readonly)
Returns the address info.
21 22 23 24 |
# File 'lib/tcp-client/address.rb', line 21 def addrinfo freeze unless @addrinfo @addrinfo end |
#host ⇒ String (readonly) Also known as: hostname
Returns the host name.
30 31 32 33 |
# File 'lib/tcp-client/address.rb', line 30 def host freeze unless @host @host end |
#port ⇒ Integer (readonly)
Returns the port number.
40 |
# File 'lib/tcp-client/address.rb', line 40 def port = addrinfo.ip_port |
Instance Method Details
#freeze ⇒ Address
Force the address resolution and prevents further modifications of itself.
102 103 104 105 106 107 108 109 |
# File 'lib/tcp-client/address.rb', line 102 def freeze unless frozen? solve @addrinfo.freeze @host.freeze end super end |
#to_h ⇒ Hash #to_h(&block) ⇒ Hash
Convert self
to a Hash containing host and port attribute.
90 |
# File 'lib/tcp-client/address.rb', line 90 def to_h(&block) = block ? to_hash.to_h(&block) : to_hash |
#to_hash ⇒ Hash
Convert self
to a Hash containing host and port attribute.
81 |
# File 'lib/tcp-client/address.rb', line 81 def to_hash = { host: host, port: port } |
#to_s ⇒ String
Returns text representation of self as "host:port".
95 |
# File 'lib/tcp-client/address.rb', line 95 def to_s = host.index(':') ? "[#{host}]:#{port}" : "#{host}:#{port}" |