Can the self object be changed inside a Proc?

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!

···

--
Posted via http://www.ruby-forum.com/.

Emmanuel, just change

  proc.call

to

  instance_eval(&proc)

Regards,
Pit

···

2007/8/22, Emmanuel Oga <oga_emmanuel_oga@yahoo.com.ar>:

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

(...)