Class: RuboCop::Cop::Performance::RedundantSortBlock
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Performance::RedundantSortBlock
- Extended by:
- AutoCorrector
- Includes:
- SortBlock
- Defined in:
- lib/rubocop/cop/performance/redundant_sort_block.rb
Overview
This cop identifies places where `sort { |a, b| a <=> b }` can be replaced with `sort`.
Constant Summary collapse
- MSG =
'Use `sort` instead of `%<bad_method>s`.'
Instance Method Summary collapse
Instance Method Details
#on_block(node) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rubocop/cop/performance/redundant_sort_block.rb', line 22 def on_block(node) return unless (send, var_a, var_b, body = sort_with_block?(node)) replaceable_body?(body, var_a, var_b) do range = sort_range(send, node) add_offense(range, message: (var_a, var_b)) do |corrector| corrector.replace(range, 'sort') end end end |