Changing the Search Order for Methods

When composing a message, you can change the default search order for methods by doing both of the following:

  1. Making the receiver object the sender object. You usually do this by specifying the special variable SELF. SELF holds the value of the object in which a method is running.
  2. Specifying a colon and a starting scope after the message name. The starting scope is a variable or environment symbol that identifies the scope object to use as the method search starting point. This scope object can be:

In A Sample Program Using Directives , an Account subclass of the Object superclass is created. It defines a TYPE method for Account, and creates the Savings subclass of Account.. The example defines a TYPE method for the Savings subclass, as follows:


SUBCLASS Option
::class Savings subclass Account
::method "TYPE"
return "a savings account"

To change the search order so Rexx searches for TYPE in the Account rather than Savings subclass, enter this instead:


Changing the Subclass Method Search Order
::method "TYPE"
return self~type:super -- returns the result of invoking the TYPE method of the superclass

When you create an asav instance of the Savings subclass and send a TYPE message to asav:

say asav~type

Rexx displays:

an account

rather than:

a savings account

because Rexx searches for TYPE in the Account class first.