Ruby 2.7 刚刚发布,它带有这些关于“位置和关键字参数分离”的新警告(请参阅他们的发布帖子)。我在玩弄它,发现还有另一个警告,我不明白。
例子:
def multiply(x:, y:)
x * y
end
args = { x: 2, y: 3 }
multiply(args)
# ./warning.rb:7: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
# ./warning.rb:1: warning: The called method `multiply' is defined here
Run Code Online (Sandbox Code Playgroud)
我认为关于弃用的第一个警告是明确的,但第二个警告The called method `multiply' is defined here让我感到困惑。
第二个警告是什么意思?和第一个警告有关吗?
添加**到调用 ( multiply(**args))时,这两个警告都会消失。
ruby ×1