Class: SimpleGraph::Graph::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_graph.rb

Overview

A internal class representing a single vertex/node inside a graph

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject (readonly)

Returns the value of attribute data.



22
23
24
# File 'lib/simple_graph.rb', line 22

def data
  @data
end

#idObject (readonly)

Returns the value of attribute id.



23
24
25
# File 'lib/simple_graph.rb', line 23

def id
  @id
end

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