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

ruby-changes:26765

From: drbrain <ko1@a...>
Date: Tue, 15 Jan 2013 09:13:29 +0900 (JST)
Subject: [ruby-changes:26765] drbrain:r38817 (trunk): * doc/syntax/methods.rdoc (Array/Hash Argument): Moved above Keyword

drbrain	2013-01-15 09:11:46 +0900 (Tue, 15 Jan 2013)

  New Revision: 38817

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38817

  Log:
    * doc/syntax/methods.rdoc (Array/Hash Argument):  Moved above Keyword
      Arguments
    * doc/syntax/methods.rdoc (Keyword Arguments):  Described ** for
      gathering arbitrary keyword arguments.

  Modified files:
    trunk/ChangeLog
    trunk/doc/syntax/methods.rdoc

Index: doc/syntax/methods.rdoc
===================================================================
--- doc/syntax/methods.rdoc	(revision 38816)
+++ doc/syntax/methods.rdoc	(revision 38817)
@@ -153,25 +153,10 @@ This will raise a SyntaxError: https://github.com/ruby/ruby/blob/trunk/doc/syntax/methods.rdoc#L153
     a + b + c
   end
 
-=== Keyword Arguments
-
-Keyword arguments are similar to positional arguments with default values:
-
-  def add_values(first: 1, second: 2)
-    first + second
-  end
-
-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.
-
-When mixing keyword arguments and positional arguments, all positional
-arguments must appear before any keyword arguments.
-
 === Array/Hash Argument
 
-Prefixing an argument with "*" causes any remaining arguments to be converted
-to an Array:
+Prefixing an argument with <code>*</code> causes any remaining arguments to be
+converted to an Array:
 
   def gather_arguments(*arguments)
     p arguments
@@ -196,6 +181,35 @@ However, this only occurs if the method https://github.com/ruby/ruby/blob/trunk/doc/syntax/methods.rdoc#L181
   gather_arguments_keyword 1, 2, three: 3
   #=> raises: unknown keyword: three (ArgumentError)
 
+Also, note that a bare <code>*</code> can be used to ignore arguments:
+
+  def ignore_arguments(*)
+  end
+
+=== Keyword Arguments
+
+Keyword arguments are similar to positional arguments with default values:
+
+  def add_values(first: 1, second: 2)
+    first + second
+  end
+
+Arbitrary keyword arguments will be accepted with <code>**</code>:
+
+  def gather_arguments(first: nil, **rest)
+    p first, rest
+  end
+
+  gather_arguments first: 1, second: 2, third: 3
+  # prints 1 then {:second=>2, :third=>3}
+
+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.
+
+When mixing keyword arguments and positional arguments, all positional
+arguments must appear before any keyword arguments.
+
 == Exception Handling
 
 Methods have an implied exception handling block so you do not need to use
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38816)
+++ ChangeLog	(revision 38817)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Jan 15 09:10:29 2013  Eric Hodel  <drbrain@s...>
+
+	* doc/syntax/methods.rdoc (Array/Hash Argument):  Moved above Keyword
+	  Arguments
+	* doc/syntax/methods.rdoc (Keyword Arguments):  Described ** for
+	  gathering arbitrary keyword arguments.
+
 Tue Jan 15 08:56:37 2013  Eric Hodel  <drbrain@s...>
 
 	* doc/syntax/calling_methods.rdoc:  Added document describing method

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

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