class RuboCop::Cop::Lint::LambdaWithoutLiteralBlock
Checks uses of lambda without a literal block. It emulates the following warning in Ruby 3.0:
% ruby -vwe 'lambda(&proc {})' ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin19] -e:1: warning: lambda without a literal block is deprecated; use the proc without lambda instead
This way, proc object is never converted to lambda. Autocorrection replaces with compatible proc argument.
@example
# bad lambda(&proc { do_something }) lambda(&Proc.new { do_something }) # good proc { do_something } Proc.new { do_something } lambda { do_something } # If you use lambda.
Constants
- MSG
- RESTRICT_ON_SEND
Public Instance Methods
on_send(node)
click to toggle source
# File lib/rubocop/cop/lint/lambda_without_literal_block.rb, line 39 def on_send(node) if node.parent&.block_type? || !node.first_argument || lambda_with_symbol_proc?(node) return end add_offense(node) do |corrector| corrector.replace(node, node.first_argument.source.delete('&')) end end