Module: Patm::DSL

Defined in:
lib/patm.rb

Instance Method Summary collapse

Instance Method Details

#define_matcher(name, &rule) ⇒ Object



666
667
668
669
670
671
672
673
674
675
676
677
678
679
# File 'lib/patm.rb', line 666

def define_matcher(name, &rule)
  rule = Rule.new(&rule).compile
  ctx = rule.context
  self.class_variable_set("@@_patm_ctx_#{name}", ctx)
  src = <<-RUBY
  def #{name}(_obj)
    _self = self
    _ctx = self.#{self.name ? 'class' : 'singleton_class'}.class_variable_get(:@@_patm_ctx_#{name})
    _match = {}
#{rule.src_body}
  end
  RUBY
  class_eval(src)
end