[ruby-talk:00322] Re: Arity features for Proc object?

From: matz@... (Yukihiro Matsumoto)
Date: 1999-05-18 00:59:45 UTC
List: ruby-talk #322
Hi.

In message "[ruby-talk:00321] Re: Arity features for Proc object?"
    on 99/05/17, GOTO Kentaro <gotoken@math.sci.hokudai.ac.jp> writes:

|Great! it seems suitable spec.  Is to use Method#arity as follows??
|
|# obj.method(:method_name).arity
|# e.g.
|	"a".method(:concat).arity  #=> 1 (correct?)

Yes. It works.

|>  proc = Proc.new{|i,| ..}      # explicitly declare single argument
|>  proc.call(a,b)
|
|Well, Is this feature - camma-trailing block parameter - documented 
|anywhare??

This is feature.  Remember the block parameters are the left hand side
of multiple assignment.  The syntax is:

        expr `,' [expr `,'...] [`*' expr] = expr [, expr...][`*' expr]
        `*' expr = expr [, expr...][`*' expr]

See? `expr, = expr' is legal left side.

|>  proc = Proc.new{|i,j| ..}     # more than two arguments
|>  proc.call(a,b,c)
|>
|>will cause ArgumentError exception, just like methods.
|>I think it does not break any existing code.
|
|I see.  It is very what I want. 

There's restriction for the argument check; Check will not done if 0
or 1 block parameter given.

|tons of thanks!!

You can check this out from Open CVS <cvs.netlab.co.jp>.

                                                matz.

In This Thread