Variable-Length arg list and blocks

Discussion in 'Ruby' started by Lolz Llolz, Aug 1, 2007.

  1. Lolz Llolz

    Lolz Llolz Guest

    Hello,
    a short question: is it possible to use variable length argument lists
    and binding associated blocks to a method parameter at the same time?
    And if it is possible, how can I do it?

    I trief the following with Ruby 1.8.2, but it didn't work:

    def test(&arg1,*args)
    end

    Of course I know, that according to the definition both modifiers have
    to be used with the last parameter.



    Turing.
    --
    Posted via http://www.ruby-forum.com/.
     
    Lolz Llolz, Aug 1, 2007
    #1
    1. Advertising

  2. Alle mercoled=C3=AC 1 agosto 2007, Lolz Llolz ha scritto:
    > Hello,
    > a short question: is it possible to use variable length argument lists
    > and binding associated blocks to a method parameter at the same time?
    > And if it is possible, how can I do it?
    >
    > I trief the following with Ruby 1.8.2, but it didn't work:
    >
    > def test(&arg1,*args)
    > end
    >
    > Of course I know, that according to the definition both modifiers have
    > to be used with the last parameter.
    >
    >
    >
    > Turing.


    You need to puts the arguments in the opposite order:

    def test(*args, &blk)
    end

    Stefano
     
    Stefano Crocco, Aug 1, 2007
    #2
    1. Advertising

  3. Lolz Llolz

    Lolz Llolz Guest

    Stefano Crocco wrote:
    > Alle mercoledì 1 agosto 2007, Lolz Llolz ha scritto:
    >> Of course I know, that according to the definition both modifiers have
    >> to be used with the last parameter.
    >>
    >>
    >>
    >> Turing.

    >
    > You need to puts the arguments in the opposite order:
    >
    > def test(*args, &blk)
    > end
    >
    > Stefano

    Your reply was very fast :)
    Thank you!



    Turing




    --
    Posted via http://www.ruby-forum.com/.
     
    Lolz Llolz, Aug 1, 2007
    #3
    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. n00m
    Replies:
    5
    Views:
    408
  2. matt
    Replies:
    1
    Views:
    287
    George Ogata
    Aug 6, 2004
  3. Sam Roberts
    Replies:
    3
    Views:
    159
    Sam Roberts
    Nov 14, 2004
  4. Replies:
    7
    Views:
    196
  5. Replies:
    21
    Views:
    400
    Barry Schwarz
    Mar 5, 2014
Loading...

Share This Page