On 3/22/08, Robert Klemme <shortcutter / googlemail.com> 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. That's not a criticism. This is a form of the lazy initialization pattern which is common in dynamic languages. The neat thing about ruby is that the instance variables don't even exist until they are needed, unlike in languages like Smalltalk where they need to be pre-declared in the class definition. I'm reminded that there used to be a tendency among some Smalltalkers to call this "laissez faire" initialization, which would be an entirely different thing I think. This just showed a lack of knowledge of French, and the use of this phrase instead of lazy initialization was one of Ralph Johnson's pet peeves IIRC. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/