class RuboCop::Cop::Lint::LambdaWithoutLiteralBlock
lambda { do_something } # If you use lambda.
Proc.new { do_something }
proc { do_something }
# good
lambda(&Proc.new { do_something })
lambda(&proc { do_something })
# bad
@example
Autocorrection replaces with compatible proc argument.
This way, proc object is never converted to lambda.
lambda instead
-e:1: warning: lambda without a literal block is deprecated; use the proc without
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin19]
$ ruby -vwe ‘lambda(&proc {})’
It emulates the following warning in Ruby 3.0:
Checks uses of lambda without a literal block.
def on_send(node)
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