From: Rick DeNatale Date: 2009-04-23T22:44:25+09:00 Subject: Re: kernal::binding problem On Thu, Apr 23, 2009 at 3:09 AM, Joel VanderWerf 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. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale