0

I know that if I have a proc created in one scope and I want to execute it in another, I have to use instance_eval to do it. But what if I want to leave the proc in the scope it was in, but I just want to give it access to variables from another scope?

The original scope of the proc is in main and I cannot just directly add variables to main. I have to add variables specifically to the proc.

After looking at the docs for binding, I noticed that it is not possible to do what I am trying to do with bindings without eval (and eval is both slow and evil) so I am looking for a better way to do this.

thesecretmaster
  • 1,950
  • 1
  • 27
  • 39
  • 2
    http://ruby-doc.org/core-2.3.1/Binding.html – Aleksei Matiushkin Aug 11 '16 at 13:51
  • This question would benefit greatly by an example. `eval` may be evil (though I disagree), but it's an essential part of Ruby. See this [SO question](http://stackoverflow.com/questions/1902744/when-is-eval-in-ruby-justified) for an interesting discussion of the value of `eval`. – Cary Swoveland Aug 11 '16 at 17:50

0 Answers0