Class: SimpleGraph::Vertex
- Inherits:
-
Object
- Object
- SimpleGraph::Vertex
- Defined in:
- lib/simple-graph.rb
Instance Attribute Summary collapse
-
#neighbors ⇒ Object
readonly
Returns the value of attribute neighbors.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #add_neighbor(vertex) ⇒ Object
-
#initialize(value, neighbors = {}) ⇒ Vertex
constructor
A new instance of Vertex.
Constructor Details
#initialize(value, neighbors = {}) ⇒ Vertex
Returns a new instance of Vertex.
8 9 10 11 |
# File 'lib/simple-graph.rb', line 8 def initialize(value, neighbors = {}) @value = value @neighbors = neighbors || {} end |
Instance Attribute Details
#neighbors ⇒ Object (readonly)
Returns the value of attribute neighbors.
6 7 8 |
# File 'lib/simple-graph.rb', line 6 def neighbors @neighbors end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
6 7 8 |
# File 'lib/simple-graph.rb', line 6 def value @value end |
Instance Method Details
#add_neighbor(vertex) ⇒ Object
13 14 15 |
# File 'lib/simple-graph.rb', line 13 def add_neighbor(vertex) neighbors[vertex.value] ||= vertex end |