mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
parent
57b7bfad9e
commit
71d21f3c75
1 changed files with 11 additions and 0 deletions
|
@ -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
|
||||
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
|
||||
arguments must appear before any keyword arguments.
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue