type at rubycentral?

Discussion in 'Ruby' started by Schüle Daniel, Mar 8, 2006.

  1. Hello


    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 ### <<< error?
    Proc.new {|a,b|}.arity » 2
    Proc.new {|a,b,c|}.arity » 3
    Proc.new {|*a|}.arity » -1
    Proc.new {|a,*b|}.arity » -2


    I would say it's a typo

    Regards, Daniel
     
    Schüle Daniel, Mar 8, 2006
    #1
    1. Advertising

  2. and one case is missing there

    irb(main):169:0> proc{}.arity
    => -1

    which means, all paramers are ignored(right?)
     
    Schüle Daniel, Mar 8, 2006
    #2
    1. Advertising

  3. Schüle Daniel, Mar 8, 2006
    #3
  4. Schüle Daniel

    James Britt Guest

    James Britt, Mar 8, 2006
    #4
  5. On Mar 8, 2006, at 10:08 AM, Sch=FCle Daniel wrote:

    > and one case is missing there
    >
    > irb(main):169:0> proc{}.arity
    > =3D> -1
    >
    > which means, all paramers are ignored(right?)
    >
    >


    Negative arities indicate the _minimum_ number of args to a proc that =20=

    takes a variable number of args

    min args =3D abs(arity + 1) if arity < 0 otherwise arity


    so a proc with no arg speciafication is the same as proc { |*args| }. =20=

    (You just can't get at the argument list)

    proc { |a, *b| } will have an arity of -2

    abs(-2 + 1) =3D 1 so it must be passed at least one arg

    proc { |a, b, c| } will have an arity of 3

    proc { || } will have an artity of zero (contrasted with proc { } )
     
    Logan Capaldo, Mar 8, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Toby
    Replies:
    3
    Views:
    3,101
    Mike Treseler
    Sep 7, 2005
  2. heyo
    Replies:
    3
    Views:
    939
    Dan Pop
    Apr 1, 2004
  3. pete
    Replies:
    4
    Views:
    809
    Dan Pop
    Apr 2, 2004
  4. Yevgen Muntyan

    #define ALLOCIT(Type) ((Type*) malloc (sizeof (Type)))

    Yevgen Muntyan, Feb 9, 2007, in forum: C Programming
    Replies:
    10
    Views:
    920
    Yevgen Muntyan
    Feb 13, 2007
  5. kj
    Replies:
    5
    Views:
    419
Loading...

Share This Page