From: Mark Wilson Date: 2002-02-01T10:14:17+09:00 Subject: Re: Newbie question about mixins I created an initialize method, and called super from the class into which I included the mixin - it didn't seem to work. Also, I don't like the idea of (and don't think a user should have to) initializing the hash table outside of the mixin - this means the user of my mixin has to know too much about it. "Mathieu Bouchard" wrote in message news:Pine.LNX.4.21.0201310114350.19519-100000@bartok... > > On Thu, 31 Jan 2002, Mark Wilson wrote: > > I have a module that I want to use as a mixin. I have defined a method > > within the module that attempts to assign a value to a hash 'slot': > > module myMod > > def mixinMethod(param1, param2) > > @hashVar[param1] = param2 > > end > > end > > I include this module into my class, and call 'mixinMethod'. I get a > > NameError because, apparently, I have not told the program that 'hashVar' is > > a hash table. Where should I do a Hash.new() or other initialization? > > you just define a #initialize method in your module and you don't believe > those who say (or assume) that you can't. > > you don't forget to call "super" first, to propagate up the chain of > methods of the same name. that chain goes through all modules and classes > that define a method of that name (in most sane cases it looks like a > "depth-first search"). > > ________________________________________________________________ > Mathieu Bouchard http://hostname.2y.net/~matju >