# Need some explnation to\_proc

**URL:** <https://www.ruby-forum.com/t/need-some-explnation-to-proc/130819>\
**Category:** Ruby\
**Created:** [March 3, 2008, 5:15pm UTC](https://www.ruby-forum.com/t/need-some-explnation-to-proc/130819 "2008-03-03T17:15:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vishy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b487fb/32.png) [@vishy](https://www.ruby-forum.com/u/vishy)\
**Post date:** [March 3, 2008, 5:15pm UTC](https://www.ruby-forum.com/t/need-some-explnation-to-proc/130819/1 "2008-03-03T17:15:45Z")

</div>

Hi,  
I am looking for some explanation for this ruby snippet.  
class Symbol  
def to\_proc  
lambda {|x, \*args| x.send(self, \*args)}  
end  
end  
words = %w(Jane, aara, multiko)  
upcase\_words = words.map(&:upcase)

What I understand is that,:upcase is a symbol,and by appending  
&,to\_proc is fired.What happens next? What is x and \*args in to\_proc ?  
thanks

---

<div class="post-metadata">

**Author:** ![vishy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b487fb/32.png) [@vishy](https://www.ruby-forum.com/u/vishy)\
**Post date:** [March 3, 2008, 5:30pm UTC](https://www.ruby-forum.com/t/need-some-explnation-to-proc/130819/2 "2008-03-03T17:30:29Z")

</div>

vishy wrote:

> What is x and \*args in to\_proc ?

They’re the arguments to the block:  
If you words.map, map will basically do:  
yield “Jane”  
yield “aara”  
yield “multiko”  
Those will be the values for x on each iteration of the block. If you’d  
use a  
method that yielded multiple values at once, the additional ones would  
go  
into args. Example:  
class Integer  
def foo(other)  
puts self+other  
end  
end  
[1,5,3].each\_with\_index(&:foo), would do the following:  
yield 1,0 # x = 1, args = [0]  
yield 5,1 # x = 5, args = [1]  
yield 3,2 # x = 3, args = [2]  
which would result in the following method calls:  
1.foo 0  
5.foo 1  
3.foo 2  
and the following output:  
1  
6  
5

HTH,  
Sebastian
