From: Charles Oliver Nutter Date: 2008-07-02T04:57:36+09:00 Subject: Re: Dynamic Variables Igal Koshevoy wrote: > I suppose if I really want to pretend like I was dynamically injecting a > local variable into a local scope, and a class/instance variable didn't > weren't desirable, then I could resort to: > > def set(name, value) > self.class.send(:attr_accessor, name) > self.send("#{name}=", value) > end > > counter = 52 > set "box#{counter}", "cat and dogs" > p box52 # => "cat and dogs" Yup, that would work except that for an attr_accessor on self you need to qualify it with self.box52...so it wouldn't be quite seamless. - Charlie