# (unknown)

**URL:** <https://rubytalk.org/t/unknown/29440>\
**Category:** ruby-talk\
**Created:** [30 July 2006 10:41 UTC](https://rubytalk.org/t/unknown/29440 "2006-07-30T10:41:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karel\_Michek](https://avatars.discourse-cdn.com/v4/letter/k/e9a140/32.png) [@Karel\_Michek](https://rubytalk.org/u/Karel_Michek)\
**Post date:** [30 July 2006 10:41 UTC](https://rubytalk.org/t/unknown/29440/1 "2006-07-30T10:41:27Z")

</div>

How should I call eval from member function that binds to global context?  
Something like

$binding = binding  
class InterpreterCallback  
&nbsp;&nbsp;&nbsp;&nbsp;def methods(expr)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;begin  
&nbsp;&nbsp;&nbsp;&nbsp;return eval(expr, $binding).class.instance\_methods(false).sort  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rescue ScriptError, StandardError  
&nbsp;&nbsp;&nbsp;&nbsp;printf "ERR: %s\n", $! || 'exception raised'  
&nbsp;&nbsp;&nbsp;&nbsp;return   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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
