From: Robert Klemme Date: 2007-12-08T20:04:59+09:00 Subject: Re: Dynamic local vars On 07.12.2007 16:48, MonkeeSage wrote: > On Dec 7, 8:33 am, Tim Hunter wrote: >> Jordan Callicoat wrote: >> >>> Not so much like a C macro, but more like a C struct...you could...use >>> a Struct ;) >>> V = Struct.new(:x, :y).new(nil, nil) >>> def bar >>> V.x = 10 >>> V.y = 20 >>> end >>> def foo >>> bar >>> puts V.x, V.y >>> end >>> Regards, >>> Jordan >> Of course the Struct is not actually allowing him to share data between >> bar and foo. It's the global constant V that's doing that. >> -- >> Posted viahttp://www.ruby-forum.com/. > > Yeah. I thought it fit the desired behavior though, since it shortened > the call to bar (as per desired behavior) and only adds four more > chars ("V." twice) over the original example. Global variables are considered harmful for a reason. Sometimes more explicitness is better. I.e. in this case I'd rather use multiple returns or - more likely - instance variables. But since I know nothing about the algorithm I cannot make a recommendation here. I'd just generally suggest to look at command pattern. Kind regards robert