# Can the self object be changed inside a Proc?

**URL:** <https://www.ruby-forum.com/t/can-the-self-object-be-changed-inside-a-proc/112747>\
**Category:** Ruby\
**Created:** [August 22, 2007, 9:23pm UTC](https://www.ruby-forum.com/t/can-the-self-object-be-changed-inside-a-proc/112747 "2007-08-22T21:23:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![emmanueloga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ecae2f/32.png) [@emmanueloga](https://www.ruby-forum.com/u/emmanueloga)\
**Post date:** [August 22, 2007, 9:23pm UTC](https://www.ruby-forum.com/t/can-the-self-object-be-changed-inside-a-proc/112747/1 "2007-08-22T21:23:36Z")

</div>

Hello, basically i want to change the self object inside a proc so i can  
do a thing like this:

the\_proc= lambda { @variable }

class Test1  
def initialize proc  
@variable= 1  
# Here i need to bind somehow the proc to the instance of Test1  
puts proc.call # should emit 1 from @variable  
end  
end

class Test2  
def initialize proc  
@variable= 2  
# Here i need to bind somehow the proc to the instance of Test2  
puts proc.call # should emit 2 from @variable  
end  
end

Test1.new  
Test2.new

That’s only an example. The real need is because of a rails application  
in wich i pass a proc that is going to be evaluated in one of the  
controller’s helpers:

```
customers_link_builder= lambda do |resource, helper|
  helper.instance_eval do
    link_to "Ver clientes", customers_path(resource)
  end
end

```

If I could bind the proc to the helper i could do better like this:

```
customers_link_builder= lambda do |resource|
  link_to "Ver clientes", customers_path(resource)
end

```

That would be very nice!!!

Thank you!

---

<div class="post-metadata">

**Author:** ![emmanueloga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ecae2f/32.png) [@emmanueloga](https://www.ruby-forum.com/u/emmanueloga)\
**Post date:** [August 22, 2007, 10:01pm UTC](https://www.ruby-forum.com/t/can-the-self-object-be-changed-inside-a-proc/112747/2 "2007-08-22T22:01:05Z")

</div>

2007/8/22, Emmanuel O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> end  
> end
> 
> (…)

Emmanuel, just change

proc.call

to

instance\_eval(&proc)

Regards,  
Pit
