class RuboCop::Cop::Performance::ReverseEach

This cop is used to identify usages of `reverse.each` and change them to use `reverse_each` instead.

@example

# bad
[].reverse.each

# good
[].reverse_each

Constants

MSG
UNDERSCORE

Public Instance Methods

autocorrect(node) click to toggle source
# File lib/rubocop/cop/performance/reverse_each.rb, line 36
def autocorrect(node)
  ->(corrector) { corrector.replace(node.loc.dot, UNDERSCORE) }
end
on_send(node) click to toggle source
# File lib/rubocop/cop/performance/reverse_each.rb, line 23
def on_send(node)
  reverse_each?(node) do |receiver|
    source_buffer = node.source_range.source_buffer
    location_of_reverse = receiver.loc.selector.begin_pos
    end_location = node.loc.selector.end_pos

    range = Parser::Source::Range.new(source_buffer,
                                      location_of_reverse,
                                      end_location)
    add_offense(node, range, MSG)
  end
end