From: Robert Klemme Date: 2006-05-23T23:41:33+09:00 Subject: Re: initializing instance variables in a module 2006/5/22, Jeff Rose : > 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...) This thread seems to have gone astray a bit but I didn't see this solution which I regard the standard way to handle this. The important part is to use initialize(*a,&b) in the module. I've put this on the wiki for easier reference: http://wiki.rubygarden.org/Ruby/page/show/InitializingWithInheritance Kind regards robert -- Have a look: http://www.flickr.com/photos/fussel-foto/