From: Stefano Zacchiroli Date: 2007-01-22T02:32:11+09:00 Subject: module global variables Is there a way to define per-module global variables? My best approximation is the following module Foo @@x = 0 def do_something_on_x @@x = ... end def x @@x end end The drawbacks are that I haven't found anything similar to attr_reader/writer/... for instance variables. If interested in the real use case here it is: I've defined a module which include a set of common functionalities which need to deliver messages with a given verbosity. I want to avoid to pass the verbosity configuration to all the involved class and methods but I want to avoid to use a global $verbosity variable since the setting should be limited to all the functionalities implemented by my module. Here is how I'm using the verbosity setting: module Foo @@verbosity = 0 def incr_verbosity @@verbosity += 1 end def verbosity @@verbosity end end I would love to write something like module Foo @@verbosity = 0 module_attr_reader :verbosity def incr_verbosity @@verbosity += 1 end end Am I using the wrong tool for my end? Many thanks in advance, Cheers. -- Stefano Zacchiroli -*- Computer Science PhD student @ Uny Bologna, Italy zack@{cs.unibo.it,debian.org,bononia.it} -%- http://www.bononia.it/zack/ (15:56:48) Zack: e la demo dema ? /\ All one has to do is hit the (15:57:15) Bac: no, la demo scema \/ right keys at the right time