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