Class: SimpleGraph::Graph::Node
- Inherits:
-
Object
- Object
- SimpleGraph::Graph::Node
- Defined in:
- lib/simple_graph.rb
Overview
A internal class representing a single vertex/node inside a graph
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#neighbors ⇒ Object
readonly
Returns the value of attribute neighbors.
Instance Method Summary collapse
-
#add_neighbor(node) ⇒ Object
Adds a neighbor to the given node.
-
#initialize(id:, data:) ⇒ Node
constructor
A new instance of Node.
Constructor Details
#initialize(id:, data:) ⇒ Node
Returns a new instance of Node
10 11 12 13 14 |
# File 'lib/simple_graph.rb', line 10 def initialize(id:, data:) @data = data @neighbors = [] @id = id end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data
22 23 24 |
# File 'lib/simple_graph.rb', line 22 def data @data end |
#id ⇒ Object (readonly)
Returns the value of attribute id
23 24 25 |
# File 'lib/simple_graph.rb', line 23 def id @id end |
#neighbors ⇒ Object (readonly)
Returns the value of attribute neighbors
21 22 23 |
# File 'lib/simple_graph.rb', line 21 def neighbors @neighbors end |
Instance Method Details
#add_neighbor(node) ⇒ Object
Adds a neighbor to the given node
17 18 19 |
# File 'lib/simple_graph.rb', line 17 def add_neighbor(node) @neighbors << node end |