Class: CycleFinder::Path
- Inherits:
-
Object
- Object
- CycleFinder::Path
- Defined in:
- backend/app/lib/cycle_finder.rb
Overview
A path is a node plus the sequence of ancestor nodes we followed to get there. A path contains a cycle if the current node also appears in the sequence of ancestors (meaning we doubled back)
Instance Attribute Summary collapse
-
#ancestors ⇒ Object
readonly
Returns the value of attribute ancestors.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Instance Method Summary collapse
-
#contains_cycle? ⇒ Boolean
-
#initialize(node, ancestors = []) ⇒ Path
constructor
A new instance of Path.
-
#next_node(new_node) ⇒ Object
Constructor Details
#initialize(node, ancestors = []) ⇒ Path
Returns a new instance of Path.
87 88 89 90 |
# File 'backend/app/lib/cycle_finder.rb', line 87 def initialize(node, ancestors = []) @node = node @ancestors = ancestors end |
Instance Attribute Details
#ancestors ⇒ Object (readonly)
Returns the value of attribute ancestors
85 86 87 |
# File 'backend/app/lib/cycle_finder.rb', line 85 def ancestors @ancestors end |
#node ⇒ Object (readonly)
Returns the value of attribute node
85 86 87 |
# File 'backend/app/lib/cycle_finder.rb', line 85 def node @node end |
Instance Method Details
#contains_cycle? ⇒ Boolean
92 93 94 |
# File 'backend/app/lib/cycle_finder.rb', line 92 def contains_cycle? ancestors.include?(node) end |
#next_node(new_node) ⇒ Object
96 97 98 |
# File 'backend/app/lib/cycle_finder.rb', line 96 def next_node(new_node) self.class.new(new_node, ancestors + [node]) end |