# Array#to\_proc

**URL:** <https://discuss.rubyonrails.org/t/array-to-proc/35778>\
**Category:** rubyonrails-core\
**Created:** [October 27, 2008, 11:19pm UTC](https://discuss.rubyonrails.org/t/array-to-proc/35778 "2008-10-27T23:19:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TaQ](https://avatars.discourse-cdn.com/v4/letter/t/7c8e57/32.png) [@TaQ](https://discuss.rubyonrails.org/u/TaQ)\
**Post date:** [October 27, 2008, 11:19pm UTC](https://discuss.rubyonrails.org/t/array-to-proc/35778/1 "2008-10-27T23:19:21Z")

</div>

Hi, I made a patch some days ago:

[http://rails.lighthouseapp.com/projects/8994/tickets/1253-arrayto\_proc](http://rails.lighthouseapp.com/projects/8994/tickets/1253-arrayto_proc)

There is some time I'm using this behaviour and would like to know what you guys think about. 🙂

Thanks.

---

<div class="post-metadata">

**Author:** ![7rans](https://avatars.discourse-cdn.com/v4/letter/7/a8b319/32.png) [@7rans](https://discuss.rubyonrails.org/u/7rans)\
**Post date:** [October 28, 2008, 3:46pm UTC](https://discuss.rubyonrails.org/t/array-to-proc/35778/2 "2008-10-28T15:46:36Z")

</div>

Is this the method?

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def to\_proc &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Proc.new do |obj,\*args| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.collect {|method| obj.send(method,\*args)} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

Seems pretty good. It's general (not Rails specific) and honestly I can't think of a better use for an Array#to\_proc.

Not sure I understand how \*args fit in there. How can they even be used?

Hmm... just occurred to me, and I haven't tried it, but is this basically equivalent to:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def to\_proc &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Proc.new do |obj| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.collect{ |method| method.to\_proc[obj] } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

assuming method is always a symbol.

Not that this is a better implementation; I think it demonstrates the nature of idea well though.

T.
