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, build_from_array, build_from_hash, #compile, #execute, #opt, #opt?, #rest?

Constructor Details

#initialize(desc, src, context) ⇒ Compiled

Returns a new instance of Compiled.



104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/patm.rb', line 104

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.



119
120
121
# File 'lib/patm.rb', line 119

def src
  @src
end

#src_bodyObject (readonly)

Returns the value of attribute src_body.



118
119
120
# File 'lib/patm.rb', line 118

def src_body
  @src_body
end

Instance Method Details

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



121
122
123
# File 'lib/patm.rb', line 121

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

#inspectObject



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

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