Class: RuboCop::Cop::LambdaLiteralToMethodCorrector
- Inherits:
-
Object
- Object
- RuboCop::Cop::LambdaLiteralToMethodCorrector
- 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
- #call(corrector) ⇒ Object
-
#initialize(block_node) ⇒ LambdaLiteralToMethodCorrector
constructor
A new instance of LambdaLiteralToMethodCorrector.
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. (corrector) remove_arguments(corrector) end replace_selector(corrector) replace_delimiters(corrector) insert_arguments(corrector) end |