Class: RuboCop::Cop::Performance::Size
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
AutoCorrector,
Base
|
|
Instance Chain:
self,
Base
|
|
Inherits: |
Base
|
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
-
MSG =
# File 'lib/rubocop/cop/performance/size.rb', line 40'Use `size` instead of `count`.'
-
RESTRICT_ON_SEND =
# File 'lib/rubocop/cop/performance/size.rb', line 41%i[count].freeze
Instance Method Summary
-
#on_csend(node)
Alias for #on_send.
- #on_send(node) (also: #on_csend)
Instance Method Details
#on_csend(node)
Alias for #on_send.
# File 'lib/rubocop/cop/performance/size.rb', line 72
alias on_csend on_send
#on_send(node) Also known as: #on_csend
[ GitHub ]# 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