From: Robert Dober Date: 2008-06-27T18:38:14+09:00 Subject: Re: Is it ellegant to use a global variable to store a Logger object? On Fri, Jun 27, 2008 at 10:17 AM, Shot (Piotr Szotkowski) wrote: > Iñaki Baz Castillo: > >> El Jueves, 26 de Junio de 2008, Shot (Piotr Szotkowski) escribió: > >>> module MyProgram >>> class Logger >>> class << self >>> def debug … >>> … >>> end >>> end >>> end >>> end > >> Ok, this seems really ellegant and I've tested that I can call >> "Logger.debug..." in any submodule/subclass into the program :) > > :) > >> Just a question: Logger must use an instance of a class (real >> class Logger), so to store it I think the best option is using >> a @@class_variable into Logger module > > No – by using class << self, you're operating on the Logger object > (an instance of the class Class), and you can access its *instance* > variables. Amen grep --recursive '@@' lib && echo "Classvariables are the root of all evil ;)" Cheers Robert