public
Created

  • Download Gist
visitor_manager.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
class Car < CarElement
def initialize
# Here we build an array of objects that will be visited. This can be done
# after initialize as well; it just needs to be built before calling 'accept'.
@elements = []
@elements << Wheel.new("front left")
@elements << Wheel.new("front right")
@elements << Wheel.new("back left")
@elements << Wheel.new("back right")
@elements << Body.new
@elements << Engine.new
end
 
# go through each element and 'visit' it
def accept(visitor)
@elements.each do |element|
element.accept(visitor)
end
visitor.visit(self)
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.