Class: SimpleGraph::Vertex

Inherits:
Object
  • Object
show all
Defined in:
lib/simple-graph.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#neighborsObject (readonly)

Returns the value of attribute neighbors.



6
7
8
# File 'lib/simple-graph.rb', line 6

def neighbors
  @neighbors
end

#valueObject (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