| Path: | examples/method_missing_example.rb |
| Last Update: | Sat Apr 19 22:45:46 -0500 2008 |
Example demonstrating "around" advice for method_missing. This is a technique for avoiding collisions when different toolkits want to override method_missing in the same classes, e.g., Object. Using around advice as shown allows a toolkit to add custom behavior while invoking the "native" method_missing to handle unrecognized method calls. Note that it is essential to use around advice, not before or after advice, because neither can prevent the call to the "wrapped" method_missing, which is presumably not what you want. In this (contrived) example, an Echo class uses method_missing to simply echo the method name and arguments. An aspect is used to intercept any calls to a fictitious "log" method and handle those in a different way.