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 independent of its case.
You must surround a method name with quotation marks 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 (&percent;), creates an instance of the Cost class ( mycost), and sends a &percent; message to mycost:
say "Enter a price:" |
pull p |
mycost=.Cost~new(p) /* Create a Cost instance */ |
say "price:" mycost~price /* ask current price */ |
mycost~"&percent;" /* send &percent; (increase) message */ |
say "price:" mycost~price /* ask current price */ |
say "&percent; :" mycost~"&percent;" /* send &percent; (increase) message */ |
::class Cost /* Cost class */ |
::attribute price /* allow access from others */ |
::method init |
expose price increase /* establish direct access to these attributes */ |
use arg price /* save argument with attribute */ |
increase=25 /* increase in percent */ |
::method "&percent;" /* Increase price &percent; method */ |
expose price increase /* Produces: Enter a price. */ |
price=price*(100+increase)/100 /* increase */ |
return price /* return increased price */ |
Results (example |
Enter a price: |
100 |
price: 100 |
price: 125 |
&percent; : 156.25 |