Ruby has method_missing
, Python has getattr
. Does Boo offer something I can use to intercept method calls?
views:
207answers:
1
+7
A:
Yes, Boo has IQuackFu.
Basically, you implement IQuackFu
, which has three methods:
QuackGet
: gets called when you get a property valueQuackSet
gets called when you set a property valueQuackInvoke
: gets called when you invoke a method
Here's an example.
Mauricio Scheffer
2009-07-18 15:27:59
A small question: can Boo intercept other object's method invocations? Kinda like Groovy does with the metaclass. I'm thinking the answer's no, since it's statically typed, but I'd like to be sure.
Geo
2009-07-18 16:07:58
I don't think you can do it the same way as Groovy, but you could use an IQuackFu-enabled class to wrap/decorate another class. Your IQuackFu-enabled class could have a dictionary of methods and properties to implement expando-behavior.
Mauricio Scheffer
2009-07-18 19:04:35
Boo isn't truly dynamic like groovy, you can't change the definition of a Type at runtime. If you declare a variable as 'duck' it essentially does compiler magic to turn that into late binding against that object, which will flow through IQuackFu if it's available. There is no actual metaclass in Boo. You would need IronRuby or IronPython to get something more like the metaclass.
justin.m.chase
2009-07-21 22:32:30