1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Document required keyword argument syntax [ci skip]

Fixes [Bug #8952]
This commit is contained in:
Jeremy Evans 2019-07-19 09:58:20 -07:00
parent 57b7bfad9e
commit 71d21f3c75

View file

@ -398,6 +398,17 @@ When calling a method with keyword arguments the arguments may appear in any
order. If an unknown keyword argument is sent by the caller an ArgumentError order. If an unknown keyword argument is sent by the caller an ArgumentError
is raised. is raised.
To require a specific keyword argument, do not include a default value
for the keyword argument:
def add_values(first:, second:)
first + second
end
add_values
# ArgumentError (missing keywords: first, second)
add_values(first: 1, second: 2)
# => 3
When mixing keyword arguments and positional arguments, all positional When mixing keyword arguments and positional arguments, all positional
arguments must appear before any keyword arguments. arguments must appear before any keyword arguments.