From: ara.t.howard@... Date: 2006-07-23T23:34:25+09:00 Subject: Re: Set an instance variable before and after initialize On Sun, 23 Jul 2006, Martin Jansson wrote: > If possible, I would like to set a instance variable in an object before and > after its initialize method is executed. let initialize help you do this then: harp:~ > cat a.rb module BeforeAfterInit module InstanceMethods def before_initialize *a, &b end def after_initialize *a, &b end def initialize *a, &b before_initialize *a, &b r = super after_initialize *a, &b r end end module ClassMethods def before &b define_method 'before_initialize', &b end def after &b define_method 'after_initialize', &b end end def self.included other other.module_eval{ include InstanceMethods } other.extend ClassMethods super end end class C include BeforeAfterInit before{ @a = 40 } after{ @b = 2 } def m() @a + @b end end p C.new.m harp:~ > ruby a.rb 42 regards. -a -- suffering increases your inner strength. also, the wishing for suffering makes the suffering disappear. - h.h. the 14th dali lama