Search code examples
smalltalksqueak

How do I invoke a Squeak method when given the method name as a string?


How do I invoke a Squeak method when given the method name as a string? is it possible ?


Solution

  • Try:

    perform: aSymbol
    perform: aSymbol with: anObject
    perform: aSymbol withArguments: anArrayOfArguments
    

    Where aSymbol is your method selector. For example instead of 1 + 2 your could write:

    1 perform: #+ with: 2
    

    If your method selector is stored as a String, you have to convert it to a Symbol first:

    1 perform: '+' asSymbol with: 2
    
    5 perform: 'raisedTo:modulo:' asSymbol withArguments: #(2 3)