From: "ara.t.howard" Date: 2008-06-29T01:01:13+09:00 Subject: Re: Is it ellegant to use a global variable to store a Logger object? On Jun 28, 2008, at 9:50 AM, Shot (Piotr Szotkowski) wrote: >> >> El Viernes, 27 de Junio de 2008, Shot (Piotr Szotkowski) escribió: > >>> module ArtDecomp class Config >>> class << self >>> >>> attr_accessor :debug, :processes, :qu_method, :qv_method, :silicone >>> def init >>> @debug = false >>> @processes = 1 >>> @qu_method = :graph_merger >>> @qv_method = :graph_merger >>> @silicone = Set[Arch[4,2], Arch[5,1]] >>> end > … >>> end >>> end end >>> ArtDecomp::Config.init > >> The only I don't like about the above code is the need of using .init >> method explicitely. It could be nice if "initialize" would also work >> automatically in some way, is not possible? (of course I understand >> that we are not creating an instance here). > > Yeah, that would be the cherry on top. :) > > I couldn’t come up with any nice solution; note that you can > initialize > this class anywhere, so if you have some other place that does any > kind > of program setup, you can do it there. Otherwise, doing it right after > the class is defined is the nicest solution in my opinion. ruby classes are evaluated top down at load time so, to achieve the effect of init you just need to delete some code module ArtDecomp::Config @debug = false @processes = 1 @qu_method = :graph_merger @qv_method = :graph_merger @silicone = Set[Arch[4,2], Arch[5,1]] class << self attr_accessor :debug, :processes, :qu_method, :qv_method, :silicone end end and the 'init' code is called at load time. a @ http://codeforpeople.com/ -- we can deny everything, except that we have the possibility of being better. simply reflect on that. h.h. the 14th dalai lama