T. Onoma
1/13/2005 10:12:00 PM
I've touched on this before with the idea of a "pre" method missing, but it
has come up again for me (AOP) and I really would like to get some general
input on the subject.
The idea is essentially that if a #method_dispatch callback method were
defined, then calls would be routed through it. For example:
class C
def method_dispatch(method, *args)
case method
when 'hi', 'hey'
hello(*args)
else
send(method, *args)
end
end
def hello(name)
puts "Hello, #{name}."
end
end
C.new.hi("Bob") #=> Hello, Bob.
#send of course must bypass #method_dispatch, or perhaps there would be a
variant method for this.
The questions I have about this:
1. Might this be a generally useful/powerful mechanism?
2. What kind of problems might this create?
Something like this certainly is useful for AOP, though I don't think the lack
of it is necessarily a show stopper. But that's why I'm wondering about its
more general implications.
Thanks,
trans.