Class: RuboCop::Cop::Performance::DoubleStartEndWith
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Performance::DoubleStartEndWith
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/performance/double_start_end_with.rb
Overview
Checks for double ‘#start_with?` or `#end_with?` calls separated by `||`. In some cases such calls can be replaced with an single `#start_with?`/`#end_with?` call.
‘IncludeActiveSupportAliases` configuration option is used to check for `starts_with?` and `ends_with?`. These methods are defined by Active Support.
Constant Summary collapse
- MSG =
'Use `%<replacement>s` instead of `%<original_code>s`.'
Instance Method Summary collapse
Instance Method Details
#on_or(node) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rubocop/cop/performance/double_start_end_with.rb', line 46 def on_or(node) receiver, method, first_call_args, second_call_args = process_source(node) return unless receiver && second_call_args.all?(&:pure?) combined_args = combine_args(first_call_args, second_call_args) add_offense(node, message: (node, receiver, first_call_args, method, combined_args)) do |corrector| autocorrect(corrector, first_call_args, second_call_args, combined_args) end end |