Task

Demonstrate how to make the object respond (sensibly/usefully) to an invocation of a method on it that it does not support through its class definitions.

Note that this is not the same as just invoking a defined method whose name is given dynamically; the method named at the point of invocation must not be defined.

This task is intended only for object systems that use a dynamic dispatch mechanism without static checking.



Related task

   Send an unknown method call.


 
load "stdlibcore.ring"
 
new test {
    anyMethodThatDoesNotExist()	# Define and call the new method
    anyMethodThatDoesNotExist()	# Call the new method
}
 
class test
      func braceerror        
           if substr(cCatchError,"Error (R3)")
	      ? "You are calling a method that doesn't exist!"
	      aError = Split(cCatchError," ")
	      cMethodName = aError[len(aError)]
	      ? "The Method Name: " + cMethodName
	      AddMethod(self,cMethodName,func {
		        ? "Hello from the new method!"
	                })
	      ? "We defined the new method!"
	      call cMethodName()
           ok
 