Class: MJ::Visitable

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

Direct Known Subclasses

BuildTool::Cfg::Node

Instance Method Summary collapse

Instance Method Details

#accept(visitor) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/mj/visitor.rb', line 7

def accept( visitor )
    raise "#{visitor.class} is not a visitable class" if visitor.instance_of? VisitorBase
    method_name = nil
    klass = self.class.ancestors.find do |ancestor|
        method_name = "visit_#{ancestor.name.split('::')[-1]}"
        visitor.respond_to?( method_name )
    end

    if klass
        return visitor.send( method_name, self )
    else
        raise "#{visitor.class}: Should not happen!"
    end
end