Sha256: 3a42f0e9df38b88e9667b1f366fd7c1787d7e7bcc7706ce641e8e14d87e70389

Contents?: true

Size: 442 Bytes

Versions: 27

Compression:

Stored size: 442 Bytes

Contents

module Johnson
  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}' at line #{line}"
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 5 rubygems

Version Path
jbarnette-johnson-1.0.0.200806240111 lib/johnson/visitable.rb
jbarnette-johnson-1.0.0.200807291507 lib/johnson/visitable.rb
jbarnette-johnson-1.0.0.200808062051 lib/johnson/visitable.rb
jbarnette-johnson-1.0.0.200808062111 lib/johnson/visitable.rb
jbarnette-johnson-1.0.0.200811251942 lib/johnson/visitable.rb
jbarnette-johnson-1.0.0.20081126120511 lib/johnson/visitable.rb
jbarnette-johnson-1.0.0.20090127202936 lib/johnson/visitable.rb
jbarnette-johnson-1.0.0.20090225110820 lib/johnson/visitable.rb
jbarnette-johnson-1.0.0.20090326122910 lib/johnson/visitable.rb
jbarnette-johnson-1.0.0.20090326154650 lib/johnson/visitable.rb
jbarnette-johnson-1.0.0.20090326161333 lib/johnson/visitable.rb
jbarnette-johnson-1.0.0.20090402144841 lib/johnson/visitable.rb
jbarnette-johnson-1.0.0.20090402155420 lib/johnson/visitable.rb
johnson19-2.0.0.pre3 lib/johnson/visitable.rb
pre-johnson-2.0.0 lib/johnson/visitable.rb
johnson-2.0.0.pre3 lib/johnson/visitable.rb
johnson-2.0.0.pre2 lib/johnson/visitable.rb
johnson-2.0.0.pre1 lib/johnson/visitable.rb
johnson-2.0.0.pre0 lib/johnson/visitable.rb
johnson-1.2.0 lib/johnson/visitable.rb