From: ptkwt@...1.aracnet.com (Phil Tomson) Date: 2002-01-31T11:24:57+09:00 Subject: Re: Newbie question about mixins In article , 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 First of all it should be: module MyMod because module names should be capitalized. > 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? > Probably you should define it in your class's initialize: class include MyMod def initialize @hashVar = Hash.new() end end OR you could do this: module MyMod def mixinMethod(param1, param2) unless defined? @hashVar @hashVar = {} end @hashVar[param1] = param2 end end >Thanks, >Mark Wilson >Xerox, The Document Company >mwilson@crt.xerox.com > You're welcome. Phil