Class: Visitor

Inherits:
Object
  • Object
show all
Defined in:
lib/loxby/visitors/base.rb

Overview

Base visitor class for visitor pattern. See Visitable.

Direct Known Subclasses

ASTPrinter, Interpreter, RPNConverter

Class Method Summary collapse

Class Method Details

.define_types(base_type, subtypes) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/loxby/visitors/base.rb', line 19

def self.define_types(base_type, subtypes)
  subtypes.each do |subtype|
    method_name = "visit_#{subtype}_#{base_type}"
    define_method(method_name.to_sym) do |_|
      raise NotImplementedError, "#{self.class} has not implemented ##{method_name}"
    end
  end
end