use instance_eval to execute code within the scope of an object: : instance_eval « Reflection « Ruby






use instance_eval to execute code within the scope of an object:

class MyClass
  def initialize
    @my_variable = 'Hello, world!'
  end
end

obj = MyClass.new
obj.instance_eval { puts @my_variable }

 








Related examples in the same category