...

/

State and Behavior

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 Person
def initialize(name)
@name = name
end
def name
@name
end
def password=(password)
@password = password
end
end

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. ...