From: "Brian Schröder" Date: 2005-11-16T22:52:28+09:00 Subject: Re: static variable; behaviour in ruby? On 16/11/05, Hugh Sasse wrote: > Any idea how to create or simulate a static variable in ruby? > > I want to create a variable to hold state between calls of a method, > but have the state disappear when the method goes out of scope. > I could create it in some external object but then I'd need to query > the scoping rules, and know where i was. > > I'm trying to do an instance_eval on a string containing a method such as > do_this x,y,z {block} > and I want to evaluate the block, or not, as a function of some > state against which x,y,z are compared. The code will be called several > times, but I only want the state intialized the first time the scope > is entered. > > And, just to make matters worse, there could be several independent > calls to this method within the scope, each with its own separate > state. > > Maybe there's another way to do this? > > Thank you > Hugh > > I advise that you state your basic problem, as this seems to be a problem with an ugly workaround. You can probably restructure your problem such that this is no longer needed. Brian -- http://ruby.brian-schroeder.de/ Stringed instrument chords: http://chordlist.brian-schroeder.de/