From: David Alan Black Date: 2002-08-05T06:49:48+09:00 Subject: Re: Detecting when an instance variable is created/set Hi -- On Mon, 5 Aug 2002, Harry Ohlsen wrote: > > > Unfortunately, for it to be useful to me, I'd specifically need it to > > > work in initialize() as well. > > > > I don't know why it does not work in initialize (I assumed it would). > > A dirty fix: > > > > module Initializer > > def initialize(*args) > > puts "Here I'll handle these variables: #{instance_variables.inspect}" > > end > > end > > > > module MonitorVariables > > ... > > end > > > > class Test > > def initialize(*args) > > @a = 1 > > @b = 'world' > > super(*args) > > end > > What is that super() calling? It seems to be the initialize() in Initializer, > but I don't understand why. I would have thought that it would be calling > the one from perhaps Object (since Test doesn't specifically subclass > anything else). It is indeed the initialize in Initializer. super basically looks for a method of the same name as the one being executed, but starting the search one link up in the method search chain. Including a module (as well as subclassing a class) adds to that chain. David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav