Search code examples
selectorsmalltalksqueak

Smalltalk delegation / storing message selectors


I am learning Squeak and I was wondering if there is a way to 'store' a message to be sent to an object.

For example I would like to be able to do the following :

Delegator>>performWith: arg
    |target method|
    target := MyObject new.
    method := #myMethod. "Not sure what goes here"
    target sendMessage: method withArgs: arg. "Or how this call would work"

An alternative approach would be to specify both the target and the method in a block. However it is possible to do using the above approach?


Solution

  • Well, perhaps i misunderstood your question, but you nearly guessed the answer: Send this message to your "target":

    perform: aSymbol with: anObject

    or:

    perform: aSymbol withArguments: anArrayOfArguments

    In your example:

    target perform: method with: arg