From: "Shot (Piotr Szotkowski)" Date: 2008-05-07T04:45:11+09:00 Subject: Re: attr_accessor for class variable? --JkW1gnuWHDypiMFO Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Robert Klemme: > On 05.05.2008 17:03, sayoyo Sayoyo wrote: >> Is there an equivalent for attr_acessor for the class varialbles? >> or I have to write a function each time I wish to exppse the class >> varaible to other clasess? > You can just use attr_* family of methods - but you need to apply them > to a different object, namely the singleton class of the class object: > irb(main):001:0> class Foo > irb(main):002:1> class< irb(main):003:2> attr_accessor :bar > irb(main):004:2> end > irb(main):005:1> end Is this the canonical way to have config objects in applications? So far I=E2=80=99m stuck with module ArtDecomp class Config include Singleton attr_accessor :debug, :qu_method, :qv_method, :silicone def initialize @debug =3D false @qu_method =3D :graph_merger @qv_method =3D :graph_merger @silicone =3D Set[Arch[4,2], Arch[5,1]] end def max_pins @silicone.map{|arch| arch.pins}.max end def max_pons @silicone.map{|arch| arch.pons}.max end def reset initialize end end end Hence, my code is either cropped with either Config.instance.debug ugliness or @config =3D Config.instance; #=E2=80=A6; @config.debug stuff. I=E2=80=99d like to have a clean Config.debug syntax, while still having the ability to initialise it (currently with defaults, like above; in the future with some optional Trollop stuff added). -- Shot --=20 I actually am proud of the stacking status bar. My contribution to the fast-paced world of Curses-based interfaces, we'll call it. -- William Morgan, sup-talk --JkW1gnuWHDypiMFO Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) iD8DBQFIILbGi/mCfdEo8UoRAu2XAKDMssbPLnfc6OsV/BBZC3O96CEU/gCeLwYJ TN8wZYo/A0e5+Zd+muNLzFs= =DXcx -----END PGP SIGNATURE----- --JkW1gnuWHDypiMFO--