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