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
Identifies places where sort { |a, b| a <=> b } can be replaced with sort.
Constant Summary collapse
- MSG =
'Use `sort` without block.'
Instance Method Summary collapse
-
#on_block(node) ⇒ Object
rubocop:disable-next InternalAffairs/ItblockHandler --
itblock accepts only a single block parameter. - #on_numblock(node) ⇒ Object
Instance Method Details
#on_block(node) ⇒ Object
rubocop:disable-next InternalAffairs/ItblockHandler -- it block accepts only a single block parameter.
22 23 24 25 26 27 28 |
# 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 register_offense(send, node) end end |
#on_numblock(node) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/rubocop/cop/performance/redundant_sort_block.rb', line 30 def on_numblock(node) return unless (send, arg_count, body = sort_with_numblock?(node)) return unless arg_count == 2 replaceable_body?(body, :_1, :_2) do register_offense(send, node) end end |