summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Isom <adam.r.isom@gmail.com>2020-01-16 14:42:36 -0700
committerNARUSE, Yui <naruse@airemix.jp>2020-03-13 21:31:10 +0900
commit3c93ed59773ca547239850d16f06451afbb0aeec (patch)
treed1c5b9561e6f1541d3f0fad68b551bd60d958d69
parentc3cd92582f970812be51310e377c82b6d9e7be92 (diff)
Update documentation for Array/Hash Argument section of methods.rdoc
[Bug #16514]
-rw-r--r--doc/syntax/methods.rdoc15
1 files changed, 13 insertions, 2 deletions
diff --git a/doc/syntax/methods.rdoc b/doc/syntax/methods.rdoc
index 924e31611f..c11bd449bc 100644
--- a/doc/syntax/methods.rdoc
+++ b/doc/syntax/methods.rdoc
@@ -379,12 +379,23 @@ converted to an Array:
gather_arguments 1, 2, 3 # prints [1, 2, 3]
-The array argument must be the last positional argument, it must appear before
-any keyword arguments.
+The array argument must appear before any keyword arguments.
+
+It is possible to gather arguments at the beginning or in the middle:
+
+ def gather_arguments(first_arg, *middle_arguments, last_arg)
+ p middle_arguments
+ end
+
+ gather_arguments 1, 2, 3, 4 # prints [2, 3]
The array argument will capture a Hash as the last entry if a hash was sent by
the caller after all positional arguments.
+ def gather_arguments(*arguments)
+ p arguments
+ end
+
gather_arguments 1, a: 2 # prints [1, {:a=>2}]
However, this only occurs if the method does not declare any keyword arguments.