From: Its Me Date: 2004-04-14T03:24:12+09:00 Subject: Re: global variable and dynamic binding: question "Joel VanderWerf" wrote > Would it help to hack together an object that has attrs corresponding to > global vars? This would require all references to those global vars to change (to GLOBALS.var, or GLOBALS[var]). I was hoping to avoid such a change, but some variant of this may be a fall back: My approach is simple: def binding (object, accessor, value, &block) object.with(accessor, value, &block) end class Object def with (attr, val) begin temp = self.get_attr(attr) self.set_attr(attr, val) yield ensure self.set_attr(attr, temp) end end def get_attr(attr); self.send(attr); end def set_attr(attr, val); self.send(attr.to_s + '=', val); end end # Hash, Array etc. can override get_attr and set_attr # And then some overrides for global variables ... class << theMissingGlobalObject def get_attr (global_symbol) some_getter_function (global_symbol) end def set_attr (global_symbol, value) some_setter_function (global_symbol, value) end end So I'm looking for theMissingGlobalObject. If there is no such thing I'd be interested to know why; perhaps there is some very good reason, like some tricky circularity with a global object holding on to global vars?