When writing methods, there are several special variables that are set automatically when a method runs. Rexx supports the following variables:
is set when a method is activated. Its value is the object that forms the execution context for the method (that is, the object that received the activating message).
You can use SELF to:
Send messages to the currently active object. For example, a FIND_CLUES method is running in an object called Mystery_Novel. When FIND_CLUES finds a clue, it sends a READ_LAST_PAGE message to Mystery_Novel:
Pass references regarding an object to the methods of other objects. For example, a SING method is running in object Song. The code:
Singer2~duet(self)would give the DUET method access to the same Song.
is set when a method is activated. Its value is the class object that is the usual starting point for a superclass method lookup for the SELF object. This is the first immediate superclass of the class that defined the method currently running.
The special variable SUPER lets you call a method in the superclass of an object. For example, the following Savings class has INIT methods that the Savings class, Account class, and Object class define.
::class Account ::method INIT expose balance use arg balance self~init:super /* Forwards to the Object INIT method */ ::method TYPE return "an account" ::method name attribute ::class Savings subclass Account ::method INIT expose interest_rate use arg balance, interest_rate self~init:super(balance) /* Forwards to the Account INIT method */ ::method type return "a savings account"
When the INIT method of the Savings class is called, the variable SUPER is set to the Account class object. For example:
This instruction calls the INIT method of the Account class rather than recursively calling the INIT method of the Savings class. When the INIT method of the Account class is called, the variable SUPER is assigned to the Object class. So in the Account class INIT:
calls the INIT method of the Object class.