From: "trans. (T. Onoma)" Date: 2005-01-18T15:08:50+09:00 Subject: Re: Fwd: [suby-ruby] Your all time desired fundemental Ruby mod On Tuesday 18 January 2005 12:21 am, Martin DeMello wrote: | "trans. (T. Onoma)" wrote: | > On Monday 17 January 2005 02:51 am, Martin DeMello wrote: | > | I can think of at least one good us for the current @@ variables - | > | subclassable GUI components that inherit hierarchy-shared look-and-feel | > | properties from the parent class. What would be the elegant way to do | > | this if @@ variables go per-class? | > | > You would have to do it via class instance vars. The problem with these | > IMHO is still the intialization issue, as with modules (see | > ruby-talk:121611, http://urltron.com/nd) Matz, do you think we can get | > something in the way of remedying that? For me it's one of the biggest | > sores in my code. | | How? | | class Button | @@background = BLUE | | def repaint | @background = @@background | ... | end | end | | class ImageButton < Button | end | | Now if @@background were changed to Button.@background, how would | repaint work in ImageButton? BTW I personally like your style: Button.@background ;) Try: class Button class < self def background @background ||= BLUE end end def repaint @background = self.class.background ... end end class ImageButton < Button end That's the idea. Work for you? T.