Class: RuboCop::Cop::EachToForCorrector
- Inherits:
-
Object
- Object
- RuboCop::Cop::EachToForCorrector
- Extended by:
- NodePattern::Macros
- Defined in:
- lib/rubocop/cop/correctors/each_to_for_corrector.rb
Overview
This class auto-corrects ‘#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
- #call(corrector) ⇒ Object
-
#initialize(block_node) ⇒ EachToForCorrector
constructor
A new instance of EachToForCorrector.
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(block_node) ⇒ EachToForCorrector
Returns a new instance of EachToForCorrector.
13 14 15 16 17 |
# File 'lib/rubocop/cop/correctors/each_to_for_corrector.rb', line 13 def initialize(block_node) @block_node = block_node @collection_node = block_node.send_node.receiver @argument_node = block_node.arguments end |
Instance Method Details
#call(corrector) ⇒ Object
19 20 21 |
# File 'lib/rubocop/cop/correctors/each_to_for_corrector.rb', line 19 def call(corrector) corrector.replace(offending_range, correction) end |