From: Jacob Fugal Date: 2006-02-02T01:26:28+09:00 Subject: Re: callbacks, events, notification in general On 2/1/06, Damphyr wrote: > class A > def set_callback notify > @notify=notify > end > def something > puts "something" > send(@notify) if @notify > end > end > > def coocoo > puts "hey" > end > a=A.new > a.something > a.set_callback(:coocoo) > a.something I second Ara's mention of the Observable module. That said, I'd also simplify this particular example using a block: class A def set_callback( &blk ) @notify = blk end def something puts "something" @notify.call if @notify end end a = A.new a.something a.set_callback { puts "hey" } a.something My general rule of thumb is that if something needs to be *done*, I register a proc, but if someone needs to *know*, I register an observer (using Observable). Jacob Fugal