From: gabriele renzi Date: 2003-12-16T00:41:59+09:00 Subject: Re: Subclassing Array il 15 Dec 2003 14:50:51 GMT, firstname@lastname.net (Hans Fugal) ha scritto:: >I have a simple observer-like module: >I'm hoping that most of the changing methods of Array are actually >implemented in terms of a couple of fundamental methods, e.g. insert and >delete. So I would do: > >class NotifyingArray > include Notifier > def insert(o) > super(o) > notify > end > def delete(o) > super(o) > notify > end >end > >Am I on the right track? Does anyone know which methods I would have to >override? A possible alternative may be something like this: class SimilArray def initialize(ary) @ary=ary end include Notifier def method_missing(:method,*args,&blk) @ary.send(:method,*args,&blk) end end This is a strange kind of "side inherithance", but it may work. BTW, do you know that an observer module already exist in the standard ruby lib ?