Bug #17179
closedUnexpected warning during value assignment to setter
Description
some_instance = Class.new { def some_setter=(a:, b:); end }.new
setter_params = { a: 1, b: 2 }
some_instance.some_setter = setter_params # => {:a=>1, :b=>2}
# warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
# warning: The called method `some_setter=' is defined here
some_instance.public_send(:some_setter=, **setter_params) # => nil
# No warninigs, everything is ok
If this behavior is okay, probably we need to add the ability to use the double splat operator with syntax sugar like in example below:
some_instance.some_setter = **setter_params
Updated by bestwebua (Vladislav Trotsenko) about 4 years ago
- Description updated (diff)
Updated by bestwebua (Vladislav Trotsenko) about 4 years ago
- Description updated (diff)
Updated by jeremyevans0 (Jeremy Evans) about 4 years ago
- Status changed from Open to Rejected
This is expected behavior in Ruby 2.7, due to keyword argument separation. The warning is valid because the code will cause an ArgumentError in Ruby 3.
You should not use keywords parameters if you want to assign a hash. Instead, you should have the method accept a single hash argument. Note that calling the method directly with keywords will not cause a warning. some_instance.send(:some_setter=, :a=>1, :b=>2)
doesn't warn, but some_instance.send(:some_setter=, {:a=>1, :b=>2})
does.
Updated by sawa (Tsuyoshi Sawada) about 4 years ago
- Subject changed from Unexpected warning when value assignment to setter to Unexpected warning during value assignment to setter
- Description updated (diff)
Updated by bestwebua (Vladislav Trotsenko) about 4 years ago
jeremyevans0 (Jeremy Evans) wrote in #note-3:
This is expected behavior in Ruby 2.7, due to keyword argument separation. The warning is valid because the code will cause an ArgumentError in Ruby 3.
You should not use keywords parameters if you want to assign a hash. Instead, you should have the method accept a single hash argument. Note that calling the method directly with keywords will not cause a warning.
some_instance.send(:some_setter=, :a=>1, :b=>2)
doesn't warn, butsome_instance.send(:some_setter=, {:a=>1, :b=>2})
does.
Thank you, Jeremy!