More about Methods

A method name can be any character string. When an object receives a message, REXX searches for a method whose name matches the message name.

You need to use quotation marks around a method name when it is the same as an operator. The following example illustrates how to do this correctly. It creates a new class (Cost), defines a new method (%), creates an instance of the Cost class (Mycost), and sends a % message to Mycost:

mycost = cost~new           /* Creates new instance mycost */
mycost~'%'                  /* Sends % message to mycost   */

::class Cost subclass 'Retail' /* Creates Cost, a sub-     */
                               /* class of 'Retail' class  */
  ::method "%"                 /* Creates % method         */
    expose p                   /* Produces: Enter a price. */
    say "Enter a price"        /* If the user specifies a  */
    pull p                     /* price of 100,            */
    say p*1.07                 /* produces: 107            */
    return 0


[Back: Objects with Their Own Unique Scope]
[Next: The Default Search Order for Selecting a Method]