module RuboCop::NodePattern::Macros
def def_node_matcher(method_name, pattern_str)
If the node matches, and no block is provided, the new method will
yield to the block (passing any captures as block arguments).
If the node matches, and a block is provided, the new method will
The new method will return nil if the node does not match
Define a method which applies a pattern to an AST node
def def_node_matcher(method_name, pattern_str) compiler = Compiler.new(pattern_str, 'node') src = "def #{method_name}(node = self" \ "#{compiler.emit_trailing_params});" \ "#{compiler.emit_method_code};end" location = caller_locations(1, 1).first class_eval(src, location.path, location.lineno) end