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.


define: #shell &builder: [lobby newSubSpace].
 
_@shell didNotUnderstand: message at: position
"Form a command string and execute it."
[
  position > 0
    ifTrue: [resend]
    ifFalse:
      [([| :command |
	message selector isUnarySelector ifTrue:
	  [command ; message selector.
	   message optionals pairsDo:
	     [| :key :value |
	      command ; ' -' ; (key as: String) allButFirst allButLast ; ' ' ; (value as: String)]].
	message selector isKeywordSelector ifTrue:
	  [| keywords args |
	   keywords: ((message selector as: String) splitWith: $:).
	   command ; keywords first.
	   keywords size = 1 ifTrue: "Read a string or array of arguments."
	     [args: message arguments second.
	      (args is: String) ifTrue: [command ; ' ' ; args]
				ifFalse: [args do: [| :arg | command ; ' ' ; arg]]]]] writingAs: String)
	 ifNil: [resend] ifNotNilDo: [| :cmd | [Platform run: cmd]]]
].