...

/

State and Behaviour

State and Behaviour

This lesson focuses on state, behavior and encapsulation in Ruby methods.

Data and methods

Lets have another look 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

Do you notice something?

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 to the person, but no way to ask for it. ...

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy