Update documentation for ruby2_keywords

Point out that the method should be used for backwards compatibility
with code prior to Ruby 3.0 instead of Ruby 2.7.  It's still needed
in Ruby 2.7. It isn't needed in Ruby 3.0, as the methods using it
could switch to delegating both positional and keyword arguments.

Add a link to the www.ruby-lang.org web page that goes into detail
describing when and how ruby2_keywords should be used.
This commit is contained in:
Jeremy Evans 2021-07-29 08:10:20 -07:00
Родитель 7564e066ff
Коммит 693ce6af0a
1 изменённых файлов: 9 добавлений и 6 удалений

Просмотреть файл

@ -2165,14 +2165,13 @@ rb_mod_private(int argc, VALUE *argv, VALUE module)
* methods. * methods.
* *
* This should only be used for methods that delegate keywords to another * This should only be used for methods that delegate keywords to another
* method, and only for backwards compatibility with Ruby versions before * method, and only for backwards compatibility with Ruby versions before 3.0.
* 2.7. * See https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/
* for details on why +ruby2_keywords+ exists and when and how to use it.
* *
* This method will probably be removed at some point, as it exists only * This method will probably be removed at some point, as it exists only
* for backwards compatibility. As it does not exist in Ruby versions * for backwards compatibility. As it does not exist in Ruby versions before
* before 2.7, check that the module responds to this method before calling * 2.7, check that the module responds to this method before calling it:
* it. Also, be aware that if this method is removed, the behavior of the
* method will change so that it does not pass through keywords.
* *
* module Mod * module Mod
* def foo(meth, *args, &block) * def foo(meth, *args, &block)
@ -2180,6 +2179,10 @@ rb_mod_private(int argc, VALUE *argv, VALUE module)
* end * end
* ruby2_keywords(:foo) if respond_to?(:ruby2_keywords, true) * ruby2_keywords(:foo) if respond_to?(:ruby2_keywords, true)
* end * end
*
* However, be aware that if the +ruby2_keywords+ method is removed, the
* behavior of the +foo+ method using the above approach will change so that
* the method does not pass through keywords.
*/ */
static VALUE static VALUE