From: Suraj Kurapati Date: 2008-06-24T00:10:28+09:00 Subject: Re: Is it ellegant to use a global variable to store a Logger object? Robert Klemme wrote: > On 23.06.2008 03:29, Suraj Kurapati wrote: >> I�aki Baz Castillo wrote: >>> Humm, I don't like adding "include Logging" to every classes I use since >>> sometimes I use objects, sometimes classes, so I'd also need to "extend" >>> some classes not just "include". >> >> You could use meta programming to include Logging in all nested classes >> and modules of your top-level module: > > Now things are becoming quite complex. Not really. You can refactor that bit of meta programming into its own module: module AddLoggingToNested def self.included target # ... code from previous e-mail ... extender[target] end end Now, you can add this propagation of logging functionality to any top-level module or class by simply doing: module MyProjectTopLevel # ... include AddLoggingToNested end Note that the include musts be done *after* all nested classes have been defined. That is why I put that include() statement at the bottom of the module's code. -- Posted via http://www.ruby-forum.com/.