We want to update our codebase to Ruby 3 and one of the biggest breaking change is the mix of keyword arguments with arguments in methods. This warning should show up
warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
But I've noticed when running a simple script, it just doesn't appear
# script.rb
def my_method(argument, other:)
puts "hello"
end
options = { other: "medium" }
argument = true
my_method(argument, options)
$ rvm use 2.7.5
$ ruby script.rb
hello
$ rvm use 3.0.1
$ ruby script.rb
script.rb:1:in `my_method': wrong number of arguments (given 2, expected 1; required keyword: other) (ArgumentError)
from script.rb:8:in `<main>'
It breaks as planned in Ruby 3, but doesn't show anything in the previous versions.
This behavior is the same in production for us, I couldn't spot one occurrence anywhere. I've used RUBYOPT='-W:deprecated' or even $VERBOSE = true that successfully list several other deprecation warnings except this one.
After looking around, it doesn't seem other people have this problem. Is there something I am missing here? Is there an option in Ruby? Using other versions of Ruby like 2.7.2 renders the same.
Another detail, we use Ruby on Rails ton run everything, but I believe the problem is within Ruby itself.
I've discovered a few things. First of all, Ruby 2.7.2 and later don't show warnings by default which would explain the difference of behavior in my tests. To activate them you have to use RUBYOPT
# Ruby 2.7.5
$ RUBYOPT='-W:deprecated' ruby script.rb
script.rb:8: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
script.rb:1: warning: The called method `my_method' is defined here
hello
Another point is that the $VERBOSE = true you can set later on doesn't work either to show this warning. I'm not sure exactly why, but only RUBYOPT would do the job for this specific problem.
Finally, I also had used wrongly the RUBYOPT option when starting my Rails server locally thus not seeing it working.
I hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With