From: Pit Capitain Date: 2002-08-04T23:34:41+09:00 Subject: Re: Detecting when an instance variable is created/set On 4 Aug 2002, at 22:42, Harry Ohlsen wrote: > To give you a feel for what I want to do ... > > In the constructor of, say, Album, I'd like something like this, > without forcing the user to write the "Wrapper.new()" > > class Album > def initialize(title, songs) > @title = Wrapper.new(title) > @songs = songs.map { |s| Wrapper.new(s) } > end > end > > Ie, what I want the user to be able to write is > > class Album > def initialize(title, songs) > @title = title > @songs = songs > end > end > > Now, if I could catch the "@x = ..." lines I could automate this. > > Actually, in my real system, I would only modify what gets stored in > @songs, not what gets stored in @title, but I have a way to determine > whether I need to make the conversion. > Hi Harry, if you cange the initialize method to def initialize(title, songs) self.title = title self.songs = songs end the accessor methods are called. Regards, Pit