From: ara.t.howard@... Date: 2006-05-23T06:38:45+09:00 Subject: Re: initializing instance variables in a module On Tue, 23 May 2006, Francis Cianfrocca wrote: > Looks promising but what if you have to assign to the variable? This code > throws an exception: > > module Mixin > def myvar > @myvar ||= 100 > @myvar > end > > def inc_myvar > myvar += 1 > end > end > > class Klass > include Mixin > end > > Klass.new.inc_myvar harp:~ > cat a.rb require 'traits' module Mixin trait 'myvar' => 100 def inc_myvar() myvar( myvar + 1) end end class Klass include Mixin end p Klass.new.inc_myvar harp:~ > ruby a.rb 101 -a -- be kind whenever possible... it is always possible. - h.h. the 14th dali lama