[前][次][番号順一覧][スレッド一覧]

ruby-changes:59730

From: Adam <ko1@a...>
Date: Fri, 17 Jan 2020 19:51:07 +0900 (JST)
Subject: [ruby-changes:59730] 09271acdaf (master): Update documentation for Array/Hash Argument section of methods.rdoc

https://git.ruby-lang.org/ruby.git/commit/?id=09271acdaf

From 09271acdaf8816562c882780d45306b3155152a1 Mon Sep 17 00:00:00 2001
From: Adam Isom <adam.r.isom@g...>
Date: Thu, 16 Jan 2020 14:42:36 -0700
Subject: Update documentation for Array/Hash Argument section of methods.rdoc


diff --git a/doc/syntax/methods.rdoc b/doc/syntax/methods.rdoc
index 924e316..c11bd44 100644
--- a/doc/syntax/methods.rdoc
+++ b/doc/syntax/methods.rdoc
@@ -379,12 +379,23 @@ converted to an Array: https://github.com/ruby/ruby/blob/trunk/doc/syntax/methods.rdoc#L379
 
   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.
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]