From: "Hal E. Fulton" Date: 2003-01-14T09:43:03+09:00 Subject: Re: Array_Of(AClass) ----- Original Message ----- From: "Gavin Sinclair" To: "ruby-talk ML" Sent: Monday, January 13, 2003 6:39 PM Subject: Re: Array_Of(AClass) > On Tuesday, January 14, 2003, 9:59:44 AM, dblack wrote: > > > 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. > > If it's just a single object, surely you can: > > class << the_str > def split(*args) > puts "args are #{args.join(', ')}" > super > end > end > > Which, again, is much nicer than aliasing. However, it only works on > one String instance, not all of them. Which was probably your point. I think eventually we're going to get some kind of mechanism like LISP's defadvice (I seem to recall a rumor like that). Not that I know LISP or understand defadvice -- but it sounds a little like AOP to me. It came up once when I suggested a "prior" keyword. Hal