I have the following code:
code = "def hi; \"hi!\"; end"
eval code
hi == "hi!" # true
I can access the method hi, because when it is defined in the evaluated code, it is defined as a method of the main object.
However, this also means that the evaluated code can access things I define outside of it:
def hi; "hi!"; end
eval "hi == \"hi\"" # => true
I want to have a separate namespace in which I can run evaluated code; How would I do it?
I tried playing with module_eval and using a module for the namespace, but I can't get it to define a method or a class and access that in another evaluation.