lxxxvi
lxxxvi

Reputation: 559

The called method `...' is defined here

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)).

Upvotes: 32

Views: 8665

Answers (1)

Aleksei Matiushkin
Aleksei Matiushkin

Reputation: 121000

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.

Upvotes: 35

Related Questions