From: Robert Klemme Date: 2008-03-22T22:44:55+09:00 Subject: Re: including instance methods and setting an instance varia On 22.03.2008 14:31, Rick DeNatale wrote: > On 3/22/08, Robert Klemme wrote: > >> A small addition: modules are a nice case where accessing instance >> variables via accessor methods instead of directly pays off because then >> you can centralize initialization: >> >> # a bit silly example >> module ItemManager >> def items >> @items ||= [] >> end > > I'd say that this defers rather than centralizes initialization. In > fact it might be said that it decentralizes it, since the > initialization of such instance variables don't occur in an initialize > method. I can see what you mean, but it is still in a *single* and hence central location. The alternative would be to spread the @items ||= [] all over the methods defined in the module (maybe I should've mentioned that in the first place). It's not as central as #initialize since that method is /usually/ (nut not always) used to initialize an object's state though, so I can 45% agree - but also have to 55% disagree. :-) Kind regards robert