I'm looking for a concise documentation of all hooks in Scala. A hook is any situation in the program flow where the common behavior can be intercepted. Such situations include:
I'm coming from a Ruby background where, for example, method_missing allows to intercept non-existent method calls.
Are such hooks available at all in Scala?
Matthias
There is no equivalent of method_missing in Scala 2.8 or earlier. In Scala 2.9 (under development), a Dynamic trait will be added. Unknown method calls to objects declaring the Dynamic trait will be automatically translated by the compiler to instead call invokeDynamic
. The idea is to get some of the power of dynamically typed languages in a safe and sane way, without paying the performance overhead of dynamic typing if unneeded. It also simplifies interoperability issues when calling objects defined in dynamic languages from within Scala.
Other than that, hooking in new behaviour in Scala is largely done either via classic inheritance, or by addiing new functionality to objects via implicit conversions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With