Class: Patm::Pattern::Compiled

Inherits:
Patm::Pattern show all
Defined in:
lib/patm.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Patm::Pattern

#&, #[], build_from, #compile, #execute, #opt, #opt?, #rest?

Constructor Details

#initialize(desc, src, context) ⇒ Compiled

Returns a new instance of Compiled.



96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/patm.rb', line 96

def initialize(desc, src, context)
  @desc = desc
  @context = context
  singleton_class = class <<self; self; end
  @src_body = src
  @src = <<-RUBY
  def execute(_match, _obj)
    _ctx = @context
#{src}
  end
  RUBY
  singleton_class.class_eval(@src)
end

Instance Attribute Details

#srcObject (readonly)

Returns the value of attribute src.



111
112
113
# File 'lib/patm.rb', line 111

def src
  @src
end

#src_bodyObject (readonly)

Returns the value of attribute src_body.



110
111
112
# File 'lib/patm.rb', line 110

def src_body
  @src_body
end

Instance Method Details

#compile_internal(free_index, target_name = "_obj") ⇒ Object



113
114
115
# File 'lib/patm.rb', line 113

def compile_internal(free_index, target_name = "_obj")
  raise "already compiled"
end

#inspectObject



116
# File 'lib/patm.rb', line 116

def inspect; "<compiled>#{@desc}"; end