Class: Metamorpher::Visitable::Visitor
- Inherits:
-
Object
- Object
- Metamorpher::Visitable::Visitor
- Defined in:
- lib/metamorpher/visitable/visitor.rb
Direct Known Subclasses
Builders::Ruby::VariableReplacementVisitor, Matcher::MatchingVisitor, Rewriter::SubstitutionVisitor
Instance Method Summary collapse
-
#visit(thing) ⇒ Object
This method will examine the class and ancestors of
thing
.
Instance Method Details
#visit(thing) ⇒ Object
This method will examine the class and ancestors of thing
. For each class in the “ancestors” list, it will check to see if the visitor knows how to handle that particular class. If it can’t find a handler for the thing
it will raise an exception.
11 12 13 14 15 16 17 18 |
# File 'lib/metamorpher/visitable/visitor.rb', line 11 def visit(thing) thing.class.ancestors.each do |ancestor| method_name = :"visit_#{ancestor.name.split("::").last.downcase}" return send(method_name, thing) if respond_to?(method_name) end fail ArgumentError, "Can't visit #{thing.class}" end |