...

/

Attribute Writers

Attribute Writers

Learn how to set attribute information

Setting attribute information

Imagine that a person not only needs a name but also a password. However, let’s also imagine that, at the time of the creation of a new person instance, this password is not yet known.

Instead, we want to be able to tell the person object about its email password later.

We can do this like so:

Press + to interact
class Person
def initialize(name)
@name = name
end
def name
@name
end
def password=(password)
@password = password
end
end

As we can see, the password= method does nothing else ...