Skip to content

Commit

Permalink
Fix LambdaNode ("modern" only)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre committed Aug 1, 2020
1 parent 97292ea commit 30bfe3d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/rubocop/ast/node/lambda_node.rb
Expand Up @@ -21,7 +21,7 @@ module AST
# 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
include ParameterizedNode::RestArguments
include MethodDispatchNode

# For similarity with legacy mode
Expand All @@ -44,14 +44,19 @@ def assignment_method?
false
end

# For similarity with legacy mode
def receiver
nil
end

# For similarity with legacy mode
def method_name
:lambda
end

# For similarity with legacy mode
def arguments
[]
def first_argument_index
2
end
end
end
Expand Down
20 changes: 20 additions & 0 deletions spec/rubocop/ast/lambda_node_spec.rb
@@ -0,0 +1,20 @@
# frozen_string_literal: true

# Note: specs for `lambda?` and `lambda_literal?` in `send_node_spec`
RSpec.describe RuboCop::AST::LambdaNode do
subject(:lambda_node) { parse_source(source).ast }

let(:source) { '->(a, b) { a + b }' }

describe '#receiver' do
it { expect(lambda_node.receiver).to eq nil }
end

describe '#method_name' do
it { expect(lambda_node.method_name).to eq :lambda }
end

describe '#arguments' do
it { expect(lambda_node.arguments.size).to eq 2 }
end
end

0 comments on commit 30bfe3d

Please sign in to comment.