# Proc

**URL:** <https://www.ruby-forum.com/t/proc/140374>\
**Category:** Ruby\
**Created:** [June 13, 2008, 11:36am UTC](https://www.ruby-forum.com/t/proc/140374 "2008-06-13T11:36:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [June 13, 2008, 11:36am UTC](https://www.ruby-forum.com/t/proc/140374/1 "2008-06-13T11:36:43Z")

</div>

Hi  
I am learning Ruby and I got the following code from a book.

str=’#{name} is my name, and #{nation} is my nation’  
bind=proc do  
name,nation=“Stephan”,“Ireland”  
binding  
end.call  
s2=eval(’"’+str+’"’,bind)  
puts s2 #This output Stephan is my name, and Ireland is my nation

I did not understand it totally…Could you please tell, what, bind is  
doing in s2=eval(’"’+str+’"’,bind)

hanks in advace  
Sijo

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [June 13, 2008, 1:45pm UTC](https://www.ruby-forum.com/t/proc/140374/2 "2008-06-13T13:45:39Z")

</div>

On Fri, Jun 13, 2008 at 11:36 AM, Sijo Kg [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I did not understand it totally…Could you please tell, what, bind is  
> doing in s2=eval(‘"’+str+‘"’,bind)

proc do  
name,nation=“Stephan”,“Ireland”  
binding  
end.call

This returns a binding (a relation between variables and values, so to  
speak)  
that contains the relation between name and nation to “Stephan” and  
“Ireland”.  
You then assign that binding to variable “bind”.

Now, eval supports a second parameter to specify the binding in which  
eval should work. This means that when eval needs to retrieve the value  
of  
a local variable it will look in the specified binding.  
So by evaluating a piece of code that contains name and nation under  
the above binding will result in values “Stephan” and “Ireland”.

Hope this helps,

Jesus.

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [June 14, 2008, 6:33am UTC](https://www.ruby-forum.com/t/proc/140374/3 "2008-06-14T06:33:58Z")

</div>

Hi  
Thanks for giving me very nice explanation…Now I understood.

Sijo
