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.



89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/patm.rb', line 89

def initialize(desc, src, context)
  @desc = desc
  @context = context
  singleton_class = class <<self; self; end
  @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.



102
103
104
# File 'lib/patm.rb', line 102

def src
  @src
end

Instance Method Details

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



104
105
106
# File 'lib/patm.rb', line 104

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

#inspectObject



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

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