From: "Simon Kröger" Date: 2006-05-23T06:43:21+09:00 Subject: Re: initializing instance variables in a module Francis Cianfrocca wrote: > Looks promising but what if you have to assign to the variable? This code > throws an exception: [...] > def inc_myvar > myvar += 1 > end > end this is equivalent to myvar = myvar + 1 which tries to initialize a *local* variable, thats not what you want. try self.myvar += 1 this of course does only work if you define a setter for myvar. module Mixin attr_writer :myvar def myvar @myvar ||= 100 @myvar end def inc_myvar self.myvar += 1 end end class Klass include Mixin end Klass.new.inc_myvar cheers Simon