Files
metasploit-gs/lib/rkelly/visitable.rb
T
James Lee 7458abc8b3 add rkelly, a javascript parsing library. this version fixes several bugs in the abandoned gem, see https://github.com/tenderlove/rkelly/pull/6
git-svn-id: file:///home/svn/framework3/trunk@12815 4d416f70-5f16-0410-b530-b9f4589650da
2011-06-02 06:31:34 +00:00

17 lines
425 B
Ruby

module RKelly
module Visitable
# Based off the visitor pattern from RubyGarden
def accept(visitor, &block)
klass = self.class.ancestors.find { |ancestor|
visitor.respond_to?("visit_#{ancestor.name.split(/::/)[-1]}")
}
if klass
visitor.send(:"visit_#{klass.name.split(/::/)[-1]}", self, &block)
else
raise "No visitor for '#{self.class}'"
end
end
end
end