From 71d21f3c750f41ab44e618162515bd9e4a9f289e Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Fri, 19 Jul 2019 09:58:20 -0700 Subject: Document required keyword argument syntax [ci skip] Fixes [Bug #8952] --- doc/syntax/methods.rdoc | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'doc/syntax/methods.rdoc') diff --git a/doc/syntax/methods.rdoc b/doc/syntax/methods.rdoc index a47c1a3cbf..564159ac01 100644 --- a/doc/syntax/methods.rdoc +++ b/doc/syntax/methods.rdoc @@ -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. -- cgit v1.2.3