Robert Klemme wrote: > "Its Me" <itsme213 / hotmail.com> schrieb im Newsbeitrag ... >>QUESTION: >>Do global variables in Ruby correspond to attributes on some object? Is >>there a way to get hold of that object and find or define accessors for >>those variables? Most specifically, if that object is referred to as >>_globals_, is there a way to define: >> def _globals_.get_attr (global_symbol) >>and >> def _globals_.set_attr (global_symbol, value) >> >>Thanks! > > > Hm, there is Kernel.global_variables() but no getter or setter, which you > could override. Do I miss something here? Would it help to hack together an object that has attrs corresponding to global vars? GLOBALS = Object.new class << GLOBALS def method_missing(m, *args, &bl) case m.to_s when /^(\w+)=$/ var = $1 if global_variables.include?( "$#{var}" ) instance_eval %{ def self.#{var}=(arg) $#{var} = arg end } end self.send m, args[0] when /^\w+$/ if global_variables.include?( "$#{m}" ) instance_eval %{ def self.#{m} $#{m} end } end self.send m else super end end end $test = 3 p GLOBALS.test GLOBALS.test = 5 p GLOBALS.test