From: Liam Date: 2007-12-08T01:28:01+09:00 Subject: Re: Dynamic local vars On Fri, Dec 07, 2007 at 10:06:15PM +0900, Tim Hunter wrote: > 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. Do they need to be "variables"? def bar(arg1,arg2) klass=class << self; self; end klass.send(:define_method,:x) { arg1 } klass.send(:define_method,:y) { arg2 } end def foo bar(42,23) puts x,y end foo Of course, x and y continue to exist after the scope of foo, but with a little more wrapping, you could solve that, too. You could create setters, but they'd have to be accessed like "self.x=".