Class: Vampire::Visitor
- Inherits:
-
Object
- Object
- Vampire::Visitor
- Defined in:
- lib/vampire/vampire.rb
Overview
Visitor contains the algorithm you want to run on the hierarchy, defined as visit or visit_with_reference It has default methods for both, subclass and override them with your custom logic, see vampire_spec.rb
Instance Attribute Summary collapse
-
#depth ⇒ Object
Returns the value of attribute depth.
-
#node ⇒ Object
Returns the value of attribute node.
Instance Method Summary collapse
-
#initialize(*args) ⇒ Visitor
constructor
A new instance of Visitor.
-
#visit(obj) ⇒ Object
return all objects in hierarchy.
-
#visit_with_reference(obj, reference_obj) ⇒ Object
compare two hierarchies.
Constructor Details
#initialize(*args) ⇒ Visitor
Returns a new instance of Visitor.
7 8 9 10 |
# File 'lib/vampire/vampire.rb', line 7 def initialize *args self.node ||= 0 self.depth ||= 0 end |
Instance Attribute Details
#depth ⇒ Object
Returns the value of attribute depth.
5 6 7 |
# File 'lib/vampire/vampire.rb', line 5 def depth @depth end |
#node ⇒ Object
Returns the value of attribute node.
5 6 7 |
# File 'lib/vampire/vampire.rb', line 5 def node @node end |
Instance Method Details
#visit(obj) ⇒ Object
return all objects in hierarchy
13 |
# File 'lib/vampire/vampire.rb', line 13 def visit(obj); obj; end |
#visit_with_reference(obj, reference_obj) ⇒ Object
compare two hierarchies
16 |
# File 'lib/vampire/vampire.rb', line 16 def visit_with_reference(obj, reference_obj); obj == reference_obj; end |