From: "Dan Stevens (IAmAI)" Date: 2007-07-06T07:28:09+09:00 Subject: Re: Calling an arbitrary method as and when an array's contents change > It sounds like you might be able to set up something like this with Observer. Ah! I'd forgotten about the observer pattern. That should do the trick. Thanks! On 05/07/07, Gregory Brown wrote: > On 7/5/07, Dan Stevens (IAmAI) wrote: > > I have a collection class that extends the Array class and I wish to > > have a particular method to be called whenever the contents of an > > instance of the class change. Can anyone advise on how I can achieve > > this? > > > > I'm aware that I can compare #hash with a previous saved value to > > determine if the contents of the instance have changed since the last > > time #hash was called. Therefore, if I can find a means of calling an > > arbitrary method or piece of code every time any method is called on > > the instance, I could achieve what I'm after. Can I override > > Object#send? > > It sounds like you might be able to set up something like this with Observer. > http://www.ruby-doc.org/stdlib/libdoc/observer/rdoc/index.html > >