Class: RuboCop::Cop::Performance::Size
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Performance::Size
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/performance/size.rb
Overview
Identifies usages of ‘count` on an `Array` and `Hash` and change them to `size`.
TODO: Add advanced detection of variables that could have been assigned to an array or a hash.
Constant Summary collapse
- MSG =
'Use `size` instead of `count`.'
- RESTRICT_ON_SEND =
%i[count].freeze
Instance Method Summary collapse
- #on_send(node) ⇒ Object (also: #on_csend)
Instance Method Details
#on_send(node) ⇒ Object Also known as: on_csend
65 66 67 68 69 70 71 |
# File 'lib/rubocop/cop/performance/size.rb', line 65 def on_send(node) return if node.parent&.block_type? || !count?(node) add_offense(node.loc.selector) do |corrector| corrector.replace(node.loc.selector, 'size') end end |