views:

22

answers:

1

Ruby has "method_missing", Tcl has "unknown", and most highly dynamic languages have an equivalent construct that is invoked when an undefined method is called. It makes perfect sense to add such functionality; something needs to happen, and there's no reason not to allow that something to be redefined by the programmer. It's rather trivial to add, and it makes for some neat "check what my language can do" demos.

Where is this behavior actually useful in real application code?

All I can think of is:

  • Maybe useful for starting a debugger without unwinding the stack (but I'm not sure if that would count as "regular application code", and an exception would work just as well in most cases).
  • For "magical" proxy objects.. ie a lazy object that gets created or loaded on first use without changing the interface (though this seems pretty easy to do by other means).

Are there other legitimate uses?

Clarification: I don't really consider "syntactical sugar to avoid having to type quotes" to be a legitimate use. Others might, I do not.

A: 

Implementing a dynamic Web Service client
http://mpathirage.com/the-importance-of-rubys-method-missing-concept/

Robert Harvey