From: Mark Hubbart Date: 2004-04-20T09:48:49+09:00 Subject: Re: proposal: call_up() for use in redefined methods On Apr 19, 2004, at 4:04 PM, Hal Fulton wrote: > Mark Hubbart wrote: > > [snip] > >> Comments? Questions? Flames? :) > > I think this is essentially the same as my suggestion in > http://ruby-talk.org/38136 Damn! you're right - and I like "prior" better, too :) I should've googled it a little better, might have turned that up. > The answer then was basically: Something like this will come > later. > > In fact, I believe that Matz's plans for pre/post/wrap would make > this sort of thing easy (and far more generalized). hmmm... from what I've read, it appears the hooks are just methods, and they can be redefined. So if you re-open a class and define foo:wrap, and foo was already wrapped, it looks like the new wrapper will replace the old one, rather than wrapping the old wrapper. The beauty of the "prior" method is that you can add support for other object types easily, by redefining the method. So if you are writing libraries for HyperNumerics and PsuedoNumerics, you just go: # file hypernumeric.rb module Math redefine :sqrt def sqrt(obj) if obj.kind_of? HyperNumeric # handle hypernumeric numbers else prior(obj) end end end # file psuedonumeric.rb module Math redefine :sqrt def sqrt(obj) if obj.kind_of? PsuedoNumeric # handle psuedonumeric numbers else prior(obj) end end end no method entanglement, no namespace clutter... And it doesn't matter which one gets defined first, since it just grabs the argument if it can handle it; otherwise it passes it on. > Unless I've misunderstood. Or me :) I might easily have misunderstood how the pre/post/wrap thing will work... I'm sorta unsure of it, the more I think about it... --Mark