This repository has been archived by the owner on Apr 22, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Keyword arguments have to be explicitly double-splatted in Ruby 2.7+
The Ruby core team decided to introduce a slight incompatibility to keyword arguments from Ruby 3.0, i.e. complete separation between keyword arguments literal and Hash literal. https://bugs.ruby-lang.org/issues/14183 ruby/ruby#2395 With that, current Ruby master warns when a Hash object was passed in as keyword arguments: ``` $ ruby -ve 'def f(x: nil) p x; end; hash = {x: 1}; f(hash)' ruby 2.7.0dev (2019-09-02T05:20:05Z master 83498854eb) [x86_64-darwin18] warning: The last argument is used as the keyword parameter warning: for `f' defined here 1 ``` To eliminate this warning, we need to prefix a "double splat" (**) to avoid ambiguity: ``` $ ruby -ve 'def f(x: nil) p x;end; hash = {x: 1}; f(**hash)' ruby 2.7.0dev (2019-09-02T05:20:05Z master 83498854eb) [x86_64-darwin18] 1 ``` See also: * ruby-i18n/i18n#486 * https://buildkite.com/rails/rails/builds/63974#7fb9ad05-a745-4022-b634-aa3eb9042b11/6-1865 ``` /usr/local/lib/ruby/gems/2.7.0/gems/mysql2-0.5.2/lib/mysql2/error.rb:55: warning: The last argument is used as the keyword parameter /usr/local/lib/ruby/gems/2.7.0/gems/mysql2-0.5.2/lib/mysql2/error.rb:94: warning: The last argument is used as the keyword parameter ```
- Loading branch information