Product Site

5.1.4.22. setMethod (Private Method)

Adds method to the receiver object's collection of object methods.

The methodname is the name of the new method. This name is translated to uppercase. If you previously defined a method with the same name using setMethod, the new method replaces the earlier one. If you omit method, setMethod makes the method name methodname unavailable for the receiver object. In this case, sending a message of that name to the receiver object runs the unknown method (if any).

The method can be either
  • a method object, or
  • a string containing a method source line, or an Array of strings containing individual method source lines (for these cases an equivalent method object is created).

The third parameter is optional, and describes if the method that is attached to an object should have OBJECT or FLOAT scope. FLOAT scope, which is the default, means that it shares the same scope with methods that were defined outside of a class. OBJECT scope means it shares the scope with other, potentially statically defined, methods of the object it is attached to.

Notes:
  1. The setMethod method is a private method (see Section 4.2.8, “Public, Package-Scope, and Private Methods”) with the additional restriction that it can only be called
    • from an instance method of the receiving object itself, or
    • from a class method in the receiving object's inheritance chain.
  2. The setMethod method is a protected method.