Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Module#ruby2_keywords

(::interned method_name, *::interned more_method_names) -> nil
ruby2_keywords(method_name, ...) → nil

Deprecated: will be removed in Ruby 4.4. Use ... argument forwarding or other delegation styles instead; they work correctly on Ruby 3.0 and later. See bugs.ruby-lang.org/issues/22205 for the schedule.

For the given method names, marks the method as passing keywords through a normal argument splat. This should only be called on methods that accept an argument splat (*args) but not explicit keywords or a keyword splat. It marks the method such that if the method is called with keyword arguments, the final hash argument is marked with a special flag such that if it is the final element of a normal argument splat to another method call, and that method call does not include explicit keywords or a keyword splat, the final element is interpreted as keywords. In other words, keywords will be passed through the method to other methods.

This should only be used for methods that delegate keywords to another method, and only for backwards compatibility with Ruby versions before 3.0. See 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.

Ruby version changes

  1. 4.1