Hi --

On Fri, 9 May 2003, Jim Freeze wrote:

> On Friday,  9 May 2003 at  8:23:52 +0900, Hal E. Fulton wrote:
> >
> > Not a stupid question... maybe my assumptions
> > don't work for you, but what I was thinking
> > was something like:
> >
> > class State
> >   @@debug = nil
> >   @@verbose = nil
> >
> >   def State.debug
> >     @@debug
> >   end
> >
> >   def State.debug=(val)
> >     @@debug = val
> >   end
> >
> >   def State.verbose
> >     @@verbose
> >   end
> >
> >   def State.verbose=(val)
> >     @@verbose = val
> >   end
> >
> > class App
> >   def main
> >     State.debug = true
> >     State.verbose = false
> >     Work.new
> >   end
> > end
> >
> > class Work
> >   def initialize
> >     puts State.debug
> >   end
> > end
> >
> > App.new.main
> >
> >
> > Hal
>
> Yes. That is the truly global solution. I was
> trying to do that but was getting lost somewhere.
>
> Is there a neater (read more concise) way to define State with
> maybe a << class_attr_accessor maybe?

You can use instance variables (of the object State) instead of class
variables, and then State becomes:

  class State
    class << self
      attr_accessor :debug, :verbose
    end
  end

(though this does not deal with the requirements you list later...)


David

-- 
David Alan Black
home: dblack / superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav