Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

class method

Hash.ruby2_keywords_hash?

Hash.ruby2_keywords_hash?(hash) → true or false

Checks if a given hash is flagged by Module#ruby2_keywords (or Proc#ruby2_keywords). This method is not for casual use; debugging, researching, and some truly necessary cases like serialization of arguments.

Example
ruby2_keywords def foo(*args)
  Hash.ruby2_keywords_hash?(args.last)
end
foo(k: 1)   #=> true
foo({k: 1}) #=> false
See also .ruby2_keywords_hash .try_convert .new #< also in 4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0