From: Vasyl Smirnov Date: 2007-12-07T22:30:28+09:00 Subject: Re: Dynamic local vars On Dec 7, 3:06 pm, Tim Hunter wrote: > Vasyl Smirnov wrote: > > Hi, > > > I wonder if there is any way to create local variables dynamically, > > for example, given > > > def foo > > bar > > puts x, y > > end > > > is it possible for bar to somehow create and initialize x and y? > > Binding doesn't seem to be modifiable.. > > > Or am I asking too much? :) > > Hmmm...local variables are called local because they're local to the > method that uses them. A variable that's shared between two methods > isn't local. > > If foo and bar are both methods in the same class, use instance > variables. If they're not both in the same class, use global variables. > Yes, instance vars are an option. Though what would be better is something like a C-style macro, which would just define and assign these local vars inside foo. I thought maybe there's a way to do it in Ruby. MonkeeSage and Tim, thank you both for your replies!