# How to create blocks with arity known at runtime

**URL:** <https://www.ruby-forum.com/t/how-to-create-blocks-with-arity-known-at-runtime/164539>\
**Category:** Ruby\
**Created:** [April 2, 2009, 12:07pm UTC](https://www.ruby-forum.com/t/how-to-create-blocks-with-arity-known-at-runtime/164539 "2009-04-02T12:07:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![abc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/2bfe46/32.png) [@abc](https://www.ruby-forum.com/u/abc)\
**Post date:** [April 2, 2009, 12:07pm UTC](https://www.ruby-forum.com/t/how-to-create-blocks-with-arity-known-at-runtime/164539/1 "2009-04-02T12:07:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![abc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/2bfe46/32.png) [@abc](https://www.ruby-forum.com/u/abc)\
**Post date:** [April 2, 2009, 12:20pm UTC](https://www.ruby-forum.com/t/how-to-create-blocks-with-arity-known-at-runtime/164539/2 "2009-04-02T12:20:55Z")

</div>

On 2 abr, 12:03, abc [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks.

I respond to myself, eval could be an option

---

<div class="post-metadata">

**Author:** ![abc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/2bfe46/32.png) [@abc](https://www.ruby-forum.com/u/abc)\
**Post date:** [April 2, 2009, 12:25pm UTC](https://www.ruby-forum.com/t/how-to-create-blocks-with-arity-known-at-runtime/164539/3 "2009-04-02T12:25:37Z")

</div>

abc [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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/56fce4adeaa79f68?hl=en](http://groups.google.com/group/comp.lang.ruby/msg/56fce4adeaa79f68?hl=en)
