Rick DeNatale wrote:
> On Thu, Apr 23, 2009 at 3:09 AM, Joel VanderWerf
> <vjoel / path.berkeley.edu> wrote:
>   
>> Tom Cloyd wrote:
>>     
>
>   
>>> eval( "moduleName.methodName", binding)
>>>
>>> Causes *crash* due to by attempt to access a variable which exists in the
>>> calling environment but not in the module. In spite of passing the binding,
>>> the method knows nothing of the variable. It's not working.
>>>
>>>       
>> You've got something like this, right?
>>
>> module M
>>  def M.meth
>>    p x
>>  end
>> end
>>
>> x = 1
>> eval "M.meth", binding # Undefined variable x
>>
>>
>> The binding that you pass into eval here only affects variables that are
>> unbound in the string. In this case there are none. The x in M.meth is a
>> bound variable in the scope of the method.
>>     
>
> And to stress the obvious
>
> eval "some string"
>
> which uses the current binding, is exactly equivalent to
>
> eval "some string", binding
>
> Assuming that binding is a call to Kernel#binding and not a local variable.
>
> So
>
> eval "M.meth"
> and
> eval "M.meth", binding
>
> will both do the same thing, including throwing any exceptions.
>
>   
So, how do I get M.meth to execute in the namespace of my main? I 
thought 'binding' packaged up that namespace and I could then pass it to 
the method. Wrong, apparently.

I want M.meth to have access to all variables in main's namespace - 
well, instance variables, anyway. How do I do that?

t.