File: lambda_node.rb

package info (click to toggle)
ruby-rubocop-ast 0.3.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 892 kB
  • sloc: ruby: 10,886; makefile: 4
file content (65 lines) | stat: -rw-r--r-- 1,370 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# frozen_string_literal: true

module RuboCop
  module AST
    # Used for modern support only:
    # Not as thoroughly tested as legacy equivalent
    #
    #   $ ruby-parse -e "->(foo) { bar }"
    #   (block
    #     (lambda)
    #     (args
    #       (arg :foo))
    #     (send nil :bar))
    #   $ ruby-parse --legacy -e "->(foo) { bar }"
    #   (block
    #     (send nil :lambda)
    #     (args
    #       (arg :foo))
    #     (send nil :bar))
    #
    # The main RuboCop runs in legacy mode; this node is only used
    # if user `AST::Builder.modernize` or `AST::Builder.emit_lambda=true`
    class LambdaNode < Node
      include ParameterizedNode::RestArguments
      include MethodDispatchNode

      # For similarity with legacy mode
      def lambda?
        true
      end

      # For similarity with legacy mode
      def lambda_literal?
        true
      end

      # For similarity with legacy mode
      def attribute_accessor?
        false
      end

      # For similarity with legacy mode
      def assignment_method?
        false
      end

      # For similarity with legacy mode
      def receiver
        nil
      end

      # For similarity with legacy mode
      def method_name
        :lambda
      end

      private

      # For similarity with legacy mode
      def first_argument_index
        2
      end
    end
  end
end