Class: RuboCop::Cop::ForToEachCorrector

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

Overview

This class auto-corrects ‘for` iteration to `#each` enumeration.

Constant Summary collapse

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

Instance Method Summary collapse

Methods included from NodePattern::Macros

def_node_matcher, def_node_search, node_search, node_search_all, node_search_body, node_search_first

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