| February 2, 2004 | Intro to Ruby | Slide #23 |
| Prev | Next |
Instance variables can't be accessed from outside a class, so you need to write accessor functions to expose a variable to the outside world. To make a "getter" method, just make a member function with the same name as the member variable (though without the @):
|
To make a "setter", put an equals sign after the method name:
|
Because this is so common, Ruby has a shorthand syntax to create them:
|
| Prev | Copyright © 2004 Walter C. Mankowski | Next |