From: Trans Date: 2007-11-27T23:24:26+09:00 Subject: Re: Metaprogramming help On Nov 27, 5:15 am, Chris Richards wrote: > Wow, thanks for all your replies. > > > BTW: To ensure a routine always runs on initialization despite > > #initialize, one way: > > > class X > > class << self > > def new(*a, &b) > > o = allocate > > o.do_your_thing > > o.initialize(*a,&b) > > o > > end > > end > > end > > > The other is AOP which is a much larger can of worms. > > so whats the simplest way to ensure this method was always run ? : > > def initialize(x=0, y=0) > self.x_position=x > self.y_position=y > end Why do you want to thwart super here? You should have very clear reason for doing so, otherwise leave it. But to answer your question directly: class X class << self def new(*a, &b) o = allocate o.pre_initialize(*a, &b) o.initialize(*a,&b) o end end def pre_initialize(x=0, y=0) self.x_position=x self.y_position=y end end T.