Class: RuboCop::Cop::EachToForCorrector

Inherits:
Object
  • Object
show all
Extended by:
Macros
Defined in:
lib/rubocop/cop/correctors/each_to_for_corrector.rb

Overview

This class autocorrects ‘#each` enumeration to `for` iteration.

Constant Summary collapse

CORRECTION_WITH_ARGUMENTS =
'for %<variables>s in %<collection>s do'
CORRECTION_WITHOUT_ARGUMENTS =
'for _ in %<enumerable>s do'

Instance Method Summary collapse

Constructor Details

#initialize(block_node) ⇒ EachToForCorrector

Returns a new instance of EachToForCorrector.



12
13
14
15
16
# File 'lib/rubocop/cop/correctors/each_to_for_corrector.rb', line 12

def initialize(block_node)
  @block_node = block_node
  @collection_node = block_node.receiver
  @argument_node = block_node.arguments
end

Instance Method Details

#call(corrector) ⇒ Object



18
19
20
# File 'lib/rubocop/cop/correctors/each_to_for_corrector.rb', line 18

def call(corrector)
  corrector.replace(offending_range, correction)
end