[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to create blocks with arity known at runtime

arcadio

4/2/2009 10:04:00 AM

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.
2 Answers

arcadio

4/2/2009 10:19:00 AM

0

On 2 abr, 12:03, abc <arcadiorubiogar...@gmail.com> wrote:
> 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.

I respond to myself, eval could be an option

pjb

4/2/2009 10:20:00 AM

0

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/56fce4adeaa7...
--
__Pascal Bourguignon__