Forum: Ruby Variable-Length arg list and blocks

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
900885f72f544f27afa77c6e1758e43b?d=identicon&s=25 Frank Meyer (turing)
on 2007-08-01 18:53
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.
C40020a47c6b625af6422b5b1302abaf?d=identicon&s=25 Stefano Crocco (crocco)
on 2007-08-01 19:01
(Received via mailing list)
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
900885f72f544f27afa77c6e1758e43b?d=identicon&s=25 Frank Meyer (turing)
on 2007-08-01 19:05
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
This topic is locked and can not be replied to.