Module: RuboCop::AST::NodePattern::MethodDefiner

Included in:
RuboCop::AST::NodePattern
Defined in:
lib/rubocop/ast/node_pattern/method_definer.rb

Overview

Functionality to turn `match_code` into methods/lambda

Instance Method Summary collapse

Instance Method Details

#as_lambdaObject


37
38
39
# File 'lib/rubocop/ast/node_pattern/method_definer.rb', line 37

def as_lambda
  eval(compile_as_lambda) # rubocop:disable Security/Eval
end

#compile_as_lambdaObject


27
28
29
30
31
32
33
34
35
# File 'lib/rubocop/ast/node_pattern/method_definer.rb', line 27

def compile_as_lambda
  <<~RUBY
    ->(#{emit_params('param0')}, block: nil) do
      #{VAR} = param0
      #{compile_init}
      #{emit_lambda_code}
    end
  RUBY
end

#def_node_matcher(base, method_name, **defaults) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rubocop/ast/node_pattern/method_definer.rb', line 8

def def_node_matcher(base, method_name, **defaults)
  def_helper(base, method_name, **defaults) do |name|
    params = emit_params('param0 = self')
    <<~RUBY
      def #{name}(#{params})
        #{VAR} = param0
        #{compile_init}
        #{emit_method_code}
      end
    RUBY
  end
end

#def_node_search(base, method_name, **defaults) ⇒ Object


21
22
23
24
25
# File 'lib/rubocop/ast/node_pattern/method_definer.rb', line 21

def def_node_search(base, method_name, **defaults)
  def_helper(base, method_name, **defaults) do |name|
    emit_node_search(name)
  end
end