From: Sandro Paganotti Date: 2008-04-29T21:25:25+09:00 Subject: Re: Mixins Well, maybe you can try this way... module Mod def Mod.included(mod) mod.class_eval <<-EOS alias_method :old_initialize, :initialize def initialize @anyvar = 10 old_initialize end EOS end def func puts @anyvar end end class MyClass def initialize #read configuration puts @anyvar @anyvar = 2 func() end include Mod end MyClass.new # => 10 # => 2 On Tue, Apr 29, 2008 at 11:03 AM, David A. Black wrote: > Hi -- > > > On Tue, 29 Apr 2008, Sandro Paganotti wrote: > > > > I don't know if I get the point but this seems work: > > > > module Mod > > @anyvar = 10 > > > > def func > > puts @anyvar > > end > > end > > > > You've got two variables called @anyvar in that code, and they have no > relation to each other. > > The first one is an instance variable belonging to the module Mod > (that is, the actual object Mod). The second one represents an > instance variable that will belong to each object that executes the > func method. > > So the @anyvar = 10 line is serving no purpose. > > > David > > -- > Rails training from David A. Black and Ruby Power and Light: > INTRO TO RAILS June 9-12 Berlin > ADVANCING WITH RAILS June 16-19 Berlin > INTRO TO RAILS June 24-27 London (Skills Matter) > See http://www.rubypal.com for details and updates! > > -- Go outside! The graphics are amazing!