arity() public

Returns the number of arguments that would not be ignored. If the block is declared to take no arguments, returns 0. If the block is known to take exactly n arguments, returns n. If the block has optional arguments, return -n-1, where n is the number of mandatory arguments. A proc with no argument declarations is the same a block declaring || as its arguments.

   Proc.new {}.arity          #=>  0
   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
Show source
Register or log in to add new notes.