Class: Evinrude::NodeInfo
- Inherits:
-
Object
- Object
- Evinrude::NodeInfo
- Defined in:
- lib/evinrude/node_info.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
-
#[](k) ⇒ Object
It's useful for a NodeInfo to be able to be treated like a hash sometimes.
- #eql?(o) ⇒ Boolean (also: #==)
- #hash ⇒ Object
-
#initialize(address:, port:, name:) ⇒ NodeInfo
constructor
A new instance of NodeInfo.
Constructor Details
#initialize(address:, port:, name:) ⇒ NodeInfo
Returns a new instance of NodeInfo.
5 6 7 |
# File 'lib/evinrude/node_info.rb', line 5 def initialize(address:, port:, name:) @address, @port, @name = address, port, name end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
3 4 5 |
# File 'lib/evinrude/node_info.rb', line 3 def address @address end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/evinrude/node_info.rb', line 3 def name @name end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
3 4 5 |
# File 'lib/evinrude/node_info.rb', line 3 def port @port end |
Instance Method Details
#[](k) ⇒ Object
It's useful for a NodeInfo to be able to be treated like a hash sometimes.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/evinrude/node_info.rb', line 10 def [](k) case k when :address @address when :port @port when :name @name else raise ArgumentError, "Invalid key #k.inspect}" end end |
#eql?(o) ⇒ Boolean Also known as: ==
23 24 25 26 27 |
# File 'lib/evinrude/node_info.rb', line 23 def eql?(o) # I know hash equality doesn't mean "equality of hashes", but it amuses # me nonetheless that that is a good way to implement it. [Evinrude::NodeInfo, Hash].include?(o.class) && { address: @address, port: @port, name: @name}.eql?({ address: o[:address], port: o[:port], name: o[:name] }) end |
#hash ⇒ Object
31 32 33 |
# File 'lib/evinrude/node_info.rb', line 31 def hash { address: @address, port: @port, name: @name }.hash end |