Class: Vertex
- Inherits:
-
Object
- Object
- Vertex
- Defined in:
- lib/vertex.rb
Instance Method Summary collapse
- #add_child(name) ⇒ Object
- #add_parent(name) ⇒ Object
- #children ⇒ Object
-
#initialize(name) ⇒ Vertex
constructor
A new instance of Vertex.
- #name ⇒ Object
- #parents ⇒ Object
- #root? ⇒ Boolean
Constructor Details
#initialize(name) ⇒ Vertex
Returns a new instance of Vertex.
2 3 4 5 6 |
# File 'lib/vertex.rb', line 2 def initialize(name) @name = name @children = [] @parents = [] end |
Instance Method Details
#add_child(name) ⇒ Object
8 9 10 |
# File 'lib/vertex.rb', line 8 def add_child(name) @children << name end |
#add_parent(name) ⇒ Object
12 13 14 |
# File 'lib/vertex.rb', line 12 def add_parent(name) @parents << name end |
#children ⇒ Object
20 21 22 |
# File 'lib/vertex.rb', line 20 def children @children end |
#name ⇒ Object
16 17 18 |
# File 'lib/vertex.rb', line 16 def name @name end |
#parents ⇒ Object
24 25 26 |
# File 'lib/vertex.rb', line 24 def parents @parents end |
#root? ⇒ Boolean
28 29 30 |
# File 'lib/vertex.rb', line 28 def root? @parents.empty? end |