Forum: Ruby How to create blocks with arity known at runtime

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.
7b00965686932462eb7c765b65c580c4?d=identicon&s=25 Arcadio Rubio garcía (abc)
on 2009-04-02 12:07
(Received via mailing list)
Hi everyone,

is it possible to create blocks of arity known at runtime, other than
simply using a variable list of params: Proc.new { |*a| ... }

I'm looking for somthing like:
params = [:a, :b]
Proc.new { |*params| ... }

which is not legal Ruby obviously

Thanks.
7b00965686932462eb7c765b65c580c4?d=identicon&s=25 Arcadio Rubio garcía (abc)
on 2009-04-02 12:20
(Received via mailing list)
On 2 abr, 12:03, abc <arcadiorubiogar...@gmail.com> wrote:
>
> Thanks.

I respond to myself, eval could be an option
9e2504e0b74e5384af09ce8a660afac4?d=identicon&s=25 Pascal J. Bourguignon (Guest)
on 2009-04-02 12:25
(Received via mailing list)
abc <arcadiorubiogarcia@gmail.com> writes:

> Hi everyone,
>
> is it possible to create blocks of arity known at runtime, other than
> simply using a variable list of params: Proc.new { |*a| ... }
>
> I'm looking for somthing like:
> params = [:a, :b]
> Proc.new { |*params| ... }
>
> which is not legal Ruby obviously

You can, using eval.
Have a look at:
http://groups.google.com/group/comp.lang.ruby/msg/...
This topic is locked and can not be replied to.