Class: AntlrGemerator::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/antlr-gemerator/template.rb

Instance Method Summary collapse

Constructor Details

#initialize(tmpl, bindings) ⇒ Template



5
6
7
8
# File 'lib/antlr-gemerator/template.rb', line 5

def initialize(tmpl, bindings)
  @tmpl = tmpl
  @bindings = bindings
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(mtd, *args, &block) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/antlr-gemerator/template.rb', line 14

def method_missing(mtd, *args, &block)
  if @bindings.include?(mtd)
    @bindings[mtd]
  else
    raise NoMethodError, "no method `#{mtd}' for #{self.class}"
  end
end

Instance Method Details

#renderObject



10
11
12
# File 'lib/antlr-gemerator/template.rb', line 10

def render
  ERB.new(@tmpl).result(binding)
end

#respond_to?(mtd) ⇒ Boolean



22
23
24
25
# File 'lib/antlr-gemerator/template.rb', line 22

def respond_to?(mtd)
  return true if @bindings.include?(mtd)
  super
end