From: gabriele renzi Date: 2003-12-15T19:01:57+09:00 Subject: Re: Arity? il Mon, 15 Dec 2003 09:52:50 +0900, "Jon A. Lambert" ha scritto:: >From the Programming Ruby - The Pragmatic Programmer's Guide: > >--class Proc --- >arity prc.arity -> anInteger > >Returns the number of arguments required by the block. If the block >takes no arguments, returns -1. If it takes one argument, returns -2. >Otherwise, returns a positive argument count unless the last argument >is prefixed with *, in which case the argument count is negated. The >number of required arguments is anInteger for positive values, and >( anInteger +1).abs otherwise. > >Proc.new {||}.arity � 0 >Proc.new {|a|}.arity � -1 >Proc.new {|a,b|}.arity � 2 >Proc.new {|a,b,c|}.arity � 3 >Proc.new {|*a|}.arity � -1 >Proc.new {|a,*b|}.arity � -2 mh I het different results: >> Proc.new do end.arity => -1 # no args >> Proc.new do|| end.arity => 0 #0 args >> Proc.new do|one| end.arity => 1 #one arg >> Proc.new do|one,two| end.arity => 2 #two arg >> Proc.new do|*maybenoargs| end.arity => -1 #no args (as minimum) about the -2.. dunno :(