From: Francis Cianfrocca Date: 2006-05-23T06:57:38+09:00 Subject: Re: initializing instance variables in a module ------=_Part_210599_5259951.1148335054337 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline We've definitely wandered into one of Ruby's darker, mustier corners. None of these solutions really sing. On 5/22/06, ara.t.howard@noaa.gov wrote: > > 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 ||=3D 100 > > @myvar > > end > > > > def inc_myvar > > myvar +=3D 1 > > end > > end > > > > class Klass > > include Mixin > > end > > > > Klass.new.inc_myvar > > harp:~ > cat a.rb > require 'traits' > > module Mixin > trait 'myvar' =3D> 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 > > ------=_Part_210599_5259951.1148335054337--