Class: Expressir::Express::Visitor::Ctx

Inherits:
Object
  • Object
show all
Defined in:
lib/expressir/express/visitor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, name) ⇒ Ctx

Returns a new instance of Ctx.



37
38
39
40
# File 'lib/expressir/express/visitor.rb', line 37

def initialize(data, name)
  @data = data
  @name = name
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



46
47
48
49
50
# File 'lib/expressir/express/visitor.rb', line 46

def method_missing(name, *args)
  rulename = name.to_s.sub(/^visit_/, "").gsub(/_([a-z])/) { |m| m[1].upcase }.to_sym
  self.class.define_method(name) { @data[rulename] }
  send name, *args
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



34
35
36
# File 'lib/expressir/express/visitor.rb', line 34

def data
  @data
end

#nameObject (readonly)

Returns the value of attribute name.



34
35
36
# File 'lib/expressir/express/visitor.rb', line 34

def name
  @name
end

#source_posObject

Returns the value of attribute source_pos.



35
36
37
# File 'lib/expressir/express/visitor.rb', line 35

def source_pos
  @source_pos
end

Instance Method Details

#each(&block) ⇒ Object



60
61
62
# File 'lib/expressir/express/visitor.rb', line 60

def each(&block)
  @data.values.each(&block)
end

#keysObject



52
53
54
# File 'lib/expressir/express/visitor.rb', line 52

def keys
  @data.keys
end

#textObject



42
43
44
# File 'lib/expressir/express/visitor.rb', line 42

def text
  str.data.to_s
end

#valuesObject



56
57
58
# File 'lib/expressir/express/visitor.rb', line 56

def values
  @data.values
end