Class: Vampire::Visitor

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#depthObject

Returns the value of attribute depth.



5
6
7
# File 'lib/vampire/vampire.rb', line 5

def depth
  @depth
end

#nodeObject

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