From: Harry Ohlsen Date: 2002-08-05T06:19:20+09:00 Subject: Re: Detecting when an instance variable is created/set > > 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). > I also don't know why, if put in MonitorVariables, initialize won't be > called, and needs to be put in a different module. I added the code in your Initializer module into MonitorVariables and it worked OK, so while it seems initialize() seems to need to be handled separately, it doesn't appear to need to be in a different module. I still have the issue, though, that with this module included, all of the instance variables end up being set to "true", rather than to the values they were actually assigned. Any idea why that is and how to fix it? > Nah, just a tad more than a rookie, really. In that case, I look forward to becoming a rookie !! Cheers, Harry O.