class RuboCop::Cop::Performance::LstripRstrip

This cop identifies places where `lstrip.rstrip` can be replaced by `strip`.

@example

@bad
'abc'.lstrip.rstrip
'abc'.rstrip.lstrip

@good
'abc'.strip

Constants

MSG

Public Instance Methods

autocorrect(node) click to toggle source
# File lib/rubocop/cop/performance/lstrip_rstrip.rb, line 33
def autocorrect(node)
  range = range_between(node.receiver.loc.selector.begin_pos,
                        node.source_range.end_pos)

  ->(corrector) { corrector.replace(range, 'strip') }
end
on_send(node) click to toggle source
# File lib/rubocop/cop/performance/lstrip_rstrip.rb, line 23
def on_send(node)
  lstrip_rstrip(node) do |first_send, method_one, method_two|
    range = range_between(first_send.loc.selector.begin_pos,
                          node.source_range.end_pos)
    add_offense(node,
                location: range,
                message: format(MSG, method_one, method_two))
  end
end