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

ruby-changes:48503

From: stomar <ko1@a...>
Date: Fri, 3 Nov 2017 05:20:16 +0900 (JST)
Subject: [ruby-changes:48503] stomar:r60618 (trunk): proc.c: improve docs for {Method, Proc}#arity

stomar	2017-11-03 05:20:11 +0900 (Fri, 03 Nov 2017)

  New Revision: 60618

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60618

  Log:
    proc.c: improve docs for {Method,Proc}#arity
    
    * proc.c: [DOC] improve Method#arity documentation to match with
      Proc#arity, mentioning keyword arguments; also make Proc#arity
      examples more consistent in the naming of keyword arguments.
      Patch by Nikita Misharin (TheSmartnik).  [Fix GH-1735]

  Modified files:
    trunk/proc.c
Index: proc.c
===================================================================
--- proc.c	(revision 60617)
+++ proc.c	(revision 60618)
@@ -938,16 +938,16 @@ rb_proc_call_with_block(VALUE self, int https://github.com/ruby/ruby/blob/trunk/proc.c#L938
  *     proc { |x:, y:, z:0| }.arity   #=>  1
  *     proc { |*a, x:, y:0| }.arity   #=> -2
  *
- *     proc   { |x=0| }.arity         #=>  0
- *     lambda { |x=0| }.arity         #=> -1
- *     proc   { |x=0, y| }.arity      #=>  1
- *     lambda { |x=0, y| }.arity      #=> -2
- *     proc   { |x=0, y=0| }.arity    #=>  0
- *     lambda { |x=0, y=0| }.arity    #=> -1
- *     proc   { |x, y=0| }.arity      #=>  1
- *     lambda { |x, y=0| }.arity      #=> -2
- *     proc   { |(x, y), z=0| }.arity #=>  1
- *     lambda { |(x, y), z=0| }.arity #=> -2
+ *     proc   { |a=0| }.arity         #=>  0
+ *     lambda { |a=0| }.arity         #=> -1
+ *     proc   { |a=0, b| }.arity      #=>  1
+ *     lambda { |a=0, b| }.arity      #=> -2
+ *     proc   { |a=0, b=0| }.arity    #=>  0
+ *     lambda { |a=0, b=0| }.arity    #=> -1
+ *     proc   { |a, b=0| }.arity      #=>  1
+ *     lambda { |a, b=0| }.arity      #=> -2
+ *     proc   { |(a, b), c=0| }.arity #=>  1
+ *     lambda { |(a, b), c=0| }.arity #=> -2
  *     proc   { |a, x:0, y:0| }.arity #=>  1
  *     lambda { |a, x:0, y:0| }.arity #=> -2
  */
@@ -2357,6 +2357,8 @@ rb_method_entry_arity(const rb_method_en https://github.com/ruby/ruby/blob/trunk/proc.c#L2357
  *  arguments, returns -n-1, where n is the number of required
  *  arguments. For methods written in C, returns -1 if the call takes a
  *  variable number of arguments.
+ *  Keywords arguments will considered as a single additional argument,
+ *  that argument being mandatory if any keyword argument is mandatory.
  *
  *     class C
  *       def one;    end
@@ -2365,6 +2367,9 @@ rb_method_entry_arity(const rb_method_en https://github.com/ruby/ruby/blob/trunk/proc.c#L2367
  *       def four(a, b); end
  *       def five(a, b, *c);    end
  *       def six(a, b, *c, &d); end
+ *       def seven(x:, y:); end
+ *       def eighth(x:, y:, **z); end
+ *       def nine(*a, x:, y:); end
  *     end
  *     c = C.new
  *     c.method(:one).arity     #=> 0
@@ -2373,6 +2378,9 @@ rb_method_entry_arity(const rb_method_en https://github.com/ruby/ruby/blob/trunk/proc.c#L2378
  *     c.method(:four).arity    #=> 2
  *     c.method(:five).arity    #=> -3
  *     c.method(:six).arity     #=> -3
+ *     c.method(:seven).arity   #=> 1
+ *     c.method(:eighth).arity  #=> 1
+ *     c.method(:nine).arity    #=> -2
  *
  *     "cat".method(:size).arity      #=> 0
  *     "cat".method(:replace).arity   #=> 1

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

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