State and Behavior
Learn why encapsulation is an important idea.
Data and methods
Let’s have another look at our class definition for Person
:
Press + to interact
class Persondef initialize(name)@name = nameenddef name@nameenddef password=(password)@password = passwordendend
Our class demonstrates an important thing about objects: There’s a way to ask a person for their name
, but no way to set a new name. On the other hand, there’s a way to set a new password, but no way to ask for it. ...