class RuboCop::Cop::ForToEachCorrector
This class autocorrects ‘for` iteration to `#each` enumeration.
def call(corrector)
def call(corrector) corrector.replace(offending_range, correction) end
def collection_end
def collection_end if collection_node.begin_type? collection_node.loc.end else collection_node.source_range end end
def collection_source
def collection_source if requires_parentheses? "(#{collection_node.source})" else collection_node.source end end
def correction
def correction format(CORRECTION, collection: collection_source, argument: variable_node.source) end
def end_position
def end_position if for_node.do? keyword_begin.end_pos else collection_end.end_pos end end
def initialize(for_node)
def initialize(for_node) @for_node = for_node @variable_node = for_node.variable @collection_node = for_node.collection end
def keyword_begin
def keyword_begin for_node.loc.begin end
def offending_range
def offending_range replacement_range(end_position) end
def replacement_range(end_pos)
def replacement_range(end_pos) Parser::Source::Range.new(for_node.source_range.source_buffer, for_node.source_range.begin_pos, end_pos) end
def requires_parentheses?
def requires_parentheses? return true if collection_node.send_type? && collection_node.operator_method? collection_node.range_type? || collection_node.or_type? || collection_node.and_type? end