From: Ryan Leavengood Date: 2006-05-23T00:59:27+09:00 Subject: Re: initializing instance variables in a module module Foo def add_stuff(key, stuff) (@foo_the_stuff ||= {})[key] = stuff end end If @foo_the_stuff is null, it will be initialized to an empty hash, otherwise the existing value will be used. I consider this use of ||= to be a Ruby idiom. Ryan On 5/22/06, Jeff Rose wrote: > Have a module: > > Module Foo > def add_stuff(key, stuff) > @foo_the_stuff[key] = stuff > end > end > > class Bar > include Foo > end > > Is there a standard or correct way to initialize @foo_the_stuff in this > example? Should the add_stuff method check whether the variable has > been initialized every time, or should this be done by implementing a > callback like append_features or included? (That's how I'd want to do > it, but it's not clear which or how...) > > Thanks, > Jeff