Class: RuboCop::Cop::Performance::RedundantBlockCall
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Performance::RedundantBlockCall
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/performance/redundant_block_call.rb
Overview
Identifies the use of a ‘&block` parameter and `block.call` where `yield` would do just as well.
Constant Summary collapse
- MSG =
'Use `yield` instead of `%<argname>s.call`.'
- YIELD =
'yield'
- OPEN_PAREN =
'('
- CLOSE_PAREN =
')'
- SPACE =
' '
Instance Method Summary collapse
- #on_def(node) ⇒ Object (also: #on_defs)
Instance Method Details
#on_def(node) ⇒ Object Also known as: on_defs
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rubocop/cop/performance/redundant_block_call.rb', line 47 def on_def(node) blockarg_def(node) do |argname, body| next unless body calls_to_report(argname, body).each do |blockcall| next if blockcall.block_literal? add_offense(blockcall, message: format(MSG, argname: argname)) do |corrector| autocorrect(corrector, blockcall) end end end end |