On Sun, 28 Nov 2004 02:26:53 +0900, trans. (T. Onoma) <transami / runbox.com> wrote: > So I was thinking/wondering if it were possible to have an a variant > initializer that _always_ calls super? it would make sense to have one for > both begin and end positions. So the above example becomes: > > module Example > def initialize_pre > @examples = [] > end > def add( ex ) > @examples << ex > end > end > > class X > include Examples > end > > When X.new is called initialize_pre automatically proceeds the #initialize > method. #initialize_post would do the same for when the #initialize method > finishes. Of course these would automatically work their way up the entire > class/module chain. > > BTW this is not necessarily the same as method wraps (consider the subtle > differences) --rather these are strictly callbacks of initialization. > > Thoughts? > T. > > One way to get this behavior now would be to implement Module#included, using it with Kernel.set_trace_func to watch instantiation for the including class, and having it call your initialize_pre and initialize_post methods. But since it's possible to have only one tracer at a time, that seems like a pretty inflexible solution. Sam