From: Jim Freeze Date: 2003-05-09T08:29:48+09:00 Subject: Re: Can a global be a constant? On Friday, 9 May 2003 at 8:16:04 +0900, dblack@superlink.net wrote: > Hi -- > > Would this be suitable? > > class App > class << self > attr_reader :state > end > State = Struct.new(:debug, :verbose) > @state = State.new(true, false) > def main > Work.new > end > end > > class Work > def initialize > puts App.state.debug > end > end > > App.new.main Close. Now, realize, I'm just now learning about this weird class << self stuff. Is that just a fancy way of doing: class App def self.state; @state; end end So, I think the problem with this is that Work does not know the name of App. So, maybe I am dreaming here, but it would be nice if I could do the following: class App def main State.new(true, true) Work.new #=> true, true State.new(false, false) Work.new #=> false, false end end I realize that I have not shown the object that gets tied to the first Work.new and another object that gets tied to the second work.new, but you get the idea. This may not be possible, because, I am implying that I also want any class that Work creates to use the same state that Work has. In leu of this option, I guess I am back to a single global state, which may best be implemented in the form of a mix-in. -- Jim Freeze ---------- Show respect for age. Drink good Scotch for a change.