From: Rick DeNatale Date: 2009-11-29T05:11:12+09:00 Subject: Re: Local variables can't be accessed from outside, right? On Sat, Nov 28, 2009 at 2:30 PM, pharrington wrote: > On Nov 28, 1:15 pm, Michael Winterstein > wrote: >> So local variables exist in some ethereal void after the code is scanned >> but before they can be used; not so with instance variables.  That makes >> some sense.  But this also lets you do this eval weirdness. >> > From what I understand, this is because local variables are created > when code is *parsed*, not actually run (as method resolution would be > even more painful if the interpreter had to first search the object > tree for a particular instance method every time a new local variable > was defined) Actually, for MRI, at compile time a local gets assigned an index which is used to dereference an element of an array of local variables pointed to by a structure called SCOPE there is a stack of these scopes which grows and shrinks as methods and blocks are called and returned.. The actual local variables need to be unique for each method invocation or block evaluation. -- 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