Module: Xcake::Visitor
- Included in:
- Generator
- Defined in:
- lib/xcake/visitor.rb
Overview
This namespace provides all of methods for implementing the Vistor in the Visitor pattern.
This implementation has a slight twist where a visitor knows when it has “left” an object it is visiting.
Classes implementing these methods should add methods ‘visit_<visitable classname>` and `leave_<visitable classname>` for each visitable they intend to use that class with.
Instance Method Summary collapse
-
#leave(item) ⇒ Object
This is called when a visitor is leaving a visitable item.
-
#visit(item) ⇒ Object
This is called when a visitor is visiting a visitable item.
Instance Method Details
#leave(item) ⇒ Object
This is called when a visitor is leaving a visitable item.
By default this method calls the method ‘leave_<visitable classname>` so make sure you’ve created a method for each visitable you intend to visit.
59 60 61 62 63 64 |
# File 'lib/xcake/visitor.rb', line 59 def leave(item) item_name = item_name(item) method = "leave_#{item_name}" send(method, item) if respond_to? method end |
#visit(item) ⇒ Object
This is called when a visitor is visiting a visitable item.
By default this method calls the method ‘visit_<visitable classname>` so make sure you’ve created a method for each visitable you intend to visit.
41 42 43 44 45 46 |
# File 'lib/xcake/visitor.rb', line 41 def visit(item) item_name = item_name(item) method = "visit_#{item_name}" send(method, item) if respond_to? method end |