From: dblack@... Date: 2003-01-14T07:59:44+09:00 Subject: Re: Array_Of(AClass) Hi -- On Mon, 13 Jan 2003, Gavin Sinclair wrote: > I want to highlight this: from a singleton class, you can use "super" > like in normal inheritance. Keep this in mind if you are redefining > methods anytime. I find the pattern > > alias_method :old_xxx, :xxx > > def xxx > ... > old_xxx > ... > end > > rather smelly. Much better is > > class << obj > def xxx > ... > super > ... > end > end > > I just learned that through this exercise, so I'm glad some good came > of it. Technique #2 is not a drop-in replacement for technique #1, though. For example, if you want to "listen in" on what a method is doing, you might do: class String alias :oldsplit :split def split(*a) puts "args are #{a.join(', ')}" oldsplit(*a) end end I don't think there's an equivalent way to do this by modifying the object's singleton class. David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav