K
Karel Michek
How should I call eval from member function that binds to global context?
Something like
$binding = binding
class InterpreterCallback
def methods(expr)
begin
return eval(expr, $binding).class.instance_methods(false).sort
rescue ScriptError, StandardError
printf "ERR: %s\n", $! || 'exception raised'
return []
end
end
end
but this does not work when I am calling InterpreterCallback::methods from C++ (for example when new local variable in the global context is created).
Also I do not understand following
This code:
puts eval("var" ).class
puts eval("var").class.instance_methods(false).sort
var = "";
produces:
NilClass
&
^
inspect
nil?
to_a
to_f
to_i
to_s
|
and this code
puts eval("var" ).class
puts eval("var").class.instance_methods(false).sort
produces
undefined local variable or method `var' for main:Object (NameError)
which is exactly what I would expect in the first case also.
Thank you
Something like
$binding = binding
class InterpreterCallback
def methods(expr)
begin
return eval(expr, $binding).class.instance_methods(false).sort
rescue ScriptError, StandardError
printf "ERR: %s\n", $! || 'exception raised'
return []
end
end
end
but this does not work when I am calling InterpreterCallback::methods from C++ (for example when new local variable in the global context is created).
Also I do not understand following
This code:
puts eval("var" ).class
puts eval("var").class.instance_methods(false).sort
var = "";
produces:
NilClass
&
^
inspect
nil?
to_a
to_f
to_i
to_s
|
and this code
puts eval("var" ).class
puts eval("var").class.instance_methods(false).sort
produces
undefined local variable or method `var' for main:Object (NameError)
which is exactly what I would expect in the first case also.
Thank you