Chapter 41. Dynamic Reception

Handle messages without defining them in the receiving class.

image

Also known as: Overriding method_missing or doesNotUnderstand

Any object has a limited set of methods defined for it. A client of an object may attempt to invoke a method that isn’t defined on the receiver. A statically typed language will spot this at compile time and report a compilation error. As a result, you know you won’t get this kind of error at runtime (unless you do some clever fiddling to get around the type system). With a dynamically typed language, you can invoke a nonexistent method at runtime, which usually gives you a runtime error.

Get Domain Specific Languages now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.