From: Ye Dingding Date: 2007-09-03T18:11:20+09:00 Subject: Re: How to extend a method? ------=_Part_11940_9427372.1188810677097 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Thanks. Maybe using ExtendA module is a good start, :) I don't want to rewrite A class directly, but i want to extend it in my app= . Indeed, i want to extend Rails::Initializer, and when i start a rails app, it can initialize the variable automatically. Module R class A attr_accessor :b def self.run init =3D new B init.send(:process) end def process initize_a end def initize_a # other action using a. end end class B attr_accessor :a def initialize self.a =3D 'a' end end end I want to add a variable 'b' and initialize it when new a B. And then do initialize_b when executing A#process. Module R class A def initialize_b end end end I think Moduel ExtendB(as what you said) can be used to add a variable 'b' and set the instance value. But how can i directly initialize_b when executing A#process? I used to get a A object and then invoke the initialize_b method. But i didn't like that way? Is there a better way to directly inject the code to the A#process? Thank you. On 9/3/07, Florian A=DFmann wrote: > > Florian A=DFmann schrieb: > > Subclass C: > > > > class B < A > > attr_accessor :b > > def intialize > > super # calls parent class (A) that already initializes @a > > @b =3D 'b' > > end > > end > > > > Regards > > Florian > > > > > > module ExtendA > attr_accessor :b > def self.included(base) > base.instance_variable_set :@b, 'b' > end > end > > class A > include ExtendA > end > > # There are probably 10^x ways to do this... > > Regards > again > > > ------=_Part_11940_9427372.1188810677097--