From: Brian Candler Date: 2009-08-11T05:33:46+09:00 Subject: Re: instance_variables vs. local_variables David Whetstone wrote: > So the implication here is that there is no way to define a local > variable at run time. There's eval with a binding. But the question is, why would you want to define a local variable at run time? Whatever problem you're trying to solve, it sounds like you're trying to solve it the wrong way. > I can use method_missing to simulate late binding of local variables, > but it is inefficient to have method_missing called every time such a > variable is referenced. I think you've just explained why Ruby works this way. A bare "foo" could be a method call, self.foo, or a local variable reference. If this were done dynamically, every single use of "foo" would be expensive. Even "foo = foo + 1" might be a self.foo on the RHS the first time it was called. But the way Ruby choses to resolve this, it knows up-front whether foo is just a cheap offset into the stack frame. if false foo = nil end foo # foo *is* a local variable -- Posted via http://www.ruby-forum.com/.