El Lunes, 23 de Junio de 2008, Suraj Kurapati escribió:
> Iñaki Baz Castillo wrote:
> > Imagine you are programming a framework
> > that others can use in their programms.
> > Isn't dangerous to extend/modify
> > Kernel module since it will be shared by *all* the code?
>
> True.  In that case, I would put the debug() method or the LOG object in
> the top-level module of my library/framework:
>
> # Using a debug() method
> module FooBar
>   module Logging
>     @@logger = Logger.new
>
>     def debug msg
>       @@logger.debug msg
>     end
>   end
>
>   class FooBar::Baz
>     include Logging  # <== NOTE this!
>
>     def oh_no
>       debug "oh no!"
>     end
>   end
> end

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".


> # Using a LOG object
> module FooBar
>   LOG = Logger.new
>
>   class FooBar::Baz
>     def oh_no
>       LOG.debug "oh no!"
>     end
>   end
> end

Ok, in this case you use a constant (LOG). This is the same I do now but I use 
a global variable ($log). Is more ellegant using a constant?

Thanks a lot.

-- 
Iñaki Baz Castillo