Project

General

Profile

Actions

Bug #19286

closed

What should kwargs' arity be?

Added by matsuda (Akira Matsuda) almost 2 years ago. Updated almost 2 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.3.0dev (2022-12-28T16:43:05Z master cada537040) +YJIT [arm64-darwin21]
[ruby-core:111522]

Description

Hello, guys. It's time for a quick Ruby quiz.

Q: What is this method's arity?
def f(a:, b:)
end

It requires two arguments, hence it should be 2?
Or if we call this method with one argument, the error message says "wrong number of arguments (given 1, expected 0; required keywords: a, b) (ArgumentError)", which means the arity is 0, maybe?

A: The answer is,
$ all-ruby -e 'p method(def f(a:, b:) end).arity'
ruby-2.1.0-preview1 0
...
ruby-2.1.0 0
ruby-2.1.1 -1
ruby-2.1.2 1
...
ruby-3.1.0 1

it's been 1 since 2.1.2. But why 1? Why not 2 nor 0?

I asked this question to the ruby-core people, and ko1's answer was that even he has no idea what the number 1 means.

So I thought it'd be worth asking this question here.


Files

random_-_ruby-lang_-_Slack.png (40.1 KB) random_-_ruby-lang_-_Slack.png matsuda (Akira Matsuda), 12/30/2022 03:04 AM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0