From: Trans Date: 2006-10-26T21:10:19+09:00 Subject: Re: Popularity Contest: Initializing Class-Level Instance Variables Phrogz wrote: > Subclassing a class that uses class-level instance variables requires > that you initialize them for subclasses. Which of the following three > techniques do you prefer? > > > TECHNIQUE 1 - EXPLICIT INITIALIZATION > ------------------------------------- > class Alpha > @foo = [] > def self.m1; @foo << rand; end > def self.m2; @foo.map{ rand }; end > end > > class Bravo < Alpha > @foo = [] > end Or: class Alpha @foo = [] def self.m1; @foo << rand; end def self.m2; @foo.map{ rand }; end def self.inherited(base) base.class_eval { @foo=[] } end end class Bravo < Alpha end T.