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.
Frank M. (Guest)
on 2007-08-01 20: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.
Stefano C. (Guest)
on 2007-08-01 21: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
Frank M. (Guest)
on 2007-08-01 21:05
Stefano C. 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.