Class: RuboCop::Cop::ForToEachCorrector
- Inherits:
-
Object
- Object
- RuboCop::Cop::ForToEachCorrector
- 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
- #call(corrector) ⇒ Object
-
#initialize(for_node) ⇒ ForToEachCorrector
constructor
A new instance of ForToEachCorrector.
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 20 21 |
# File 'lib/rubocop/cop/correctors/for_to_each_corrector.rb', line 17 def call(corrector) offending_range = for_node.source_range.begin.join(end_range) corrector.replace(offending_range, correction) end |