Class: RuboCop::Cop::LambdaLiteralToMethodCorrector

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb

Overview

This class autocorrects lambda literal to method notation.

Instance Method Summary collapse

Constructor Details

#initialize(block_node) ⇒ LambdaLiteralToMethodCorrector

Returns a new instance of LambdaLiteralToMethodCorrector.



7
8
9
10
11
# File 'lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb', line 7

def initialize(block_node)
  @block_node = block_node
  @method     = block_node.send_node
  @arguments  = block_node.arguments
end

Instance Method Details

#call(corrector) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb', line 13

def call(corrector)
  # Check for unparenthesized args' preceding and trailing whitespaces.
  remove_unparenthesized_whitespace(corrector)

  if block_node.block_type?
    # Avoid correcting to `lambdado` by inserting whitespace
    # if none exists before or after the lambda arguments.
    insert_separating_space(corrector)

    remove_arguments(corrector)
  end

  replace_selector(corrector)

  replace_delimiters(corrector)

  insert_arguments(corrector)
end