V
V
Viktor Vsk2014-12-05 22:44:08
ruby
Viktor Vsk, 2014-12-05 22:44:08

What are the ways to set the eval context?

class User

  def method
    var = "puts(@another_var)" 
    @another_var = 11
    eval(var)
  end
end

It is desirable that it would be possible to directly interact with the instance, without passing an entire copy of the object to the lambda (the first thing that came to mind)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
_
_ _, 2014-12-05
@viktorvsk

instance_eval(string [, filename [, lineno]] ) → obj
instance_eval {| | block } → obj
some_object.instance_eval do
    instance_method(10)
end
some_object.instance_eval('instance_method(10)')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question