From: Trevoke Date: 2009-07-23T04:15:15+09:00 Subject: Re: Instantiating classes / sharing data between classes On Jul 22, 1:26 pm, Gary Wright wrote: > On Jul 22, 2009, at 12:11 PM, Chris Rhoden wrote: > > > class Doctor > >  def modalities > >    @@modalities ||= your stuff > >  end > > end > > I think reaching for class variables is almost always a mistake. > Some alternatives that I would consider first: > > a) Use a constant: > > class Doctor >    Modalities = query_for_modalities > end > > b) Use a class method and lazy load the data > > class Doctor >    def self.modalities >       @modalities ||= query_for_modalities >    end > end > > I don't recommend class variables because their actual scope > is very non-intuitive (class hierarchy scope, not class scope) > and they add to the semantic load of a design when plain > old instance variables (on the class object) will do just fine. > > Gary Wright Gary -- these values ARE the same for EVERY SINGLE INSTANCE of the class, and are not meant to be changed. In this particular instance, are class variables fulfilling their destiny?