Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The called method `...' is defined here

Tags:

ruby

Ruby 2.7 was just released and it comes with these new warnings for "Separation of positional and keyword arguments" (see their Release Post). I was playing around with it and discovered that there's another warning, which I don't understand.

Example:

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 

I think the first warning about the deprecation is clear, but the second warning The called method `multiply' is defined here is confusing to me.

What does the second warning mean? Is it related to the first warning?

Both warnings disappear when adding ** to the call (multiply(**args)).

like image 292
lxxxvi Avatar asked Dec 26 '19 15:12

lxxxvi


1 Answers

What does the second warning mean? Is it related to the first warning?

There is a single warning with a text split into two lines. It literally says: args should be converted to **args, here is the call that produced this warning, here is its definition for your convenience.

like image 163
Aleksei Matiushkin Avatar answered Oct 24 '22 19:10

Aleksei Matiushkin