Class: RuboCop::Cop::ForToEachCorrector

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

Overview

This class autocorrects for iteration to #each enumeration.

Constant Summary collapse

CORRECTION =
'%<collection>s.each do |%<argument>s|'

Instance Method Summary collapse

Constructor Details

#initialize(for_node) ⇒ ForToEachCorrector

Returns a new instance of ForToEachCorrector.



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

def initialize(for_node)
  @for_node        = for_node
  @variable_node   = for_node.variable
  @collection_node = for_node.collection
end

Instance Method Details

#call(corrector) ⇒ Object



17
18
19
# File 'lib/rubocop/cop/correctors/for_to_each_corrector.rb', line 17

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