As well as getting the value of an attribute, you may well want to set or change it. The syntax you’ll use is as follows:
1 2 3 |
|
This kind of accessor is called a get-set method because you can use it to both get and set the attribute. Turning your current read–only accessors into accessors that can also set the value is simple. Let’s create a get–set method for address():
1 2 3 4 5 6 7 8 9 10 |
|
If you don’t particularly want to trap calling the method as a class method (since it’ll generate an error when we try to access the hash entry anyway), you can write really miniature get–set methods like the following:
1 2 3 4 5 |
|