6. attr_accessor


#1

Why is there two attr for job. 1 is a reader and the other is writer. Is there allowed to be more than 1 attr for the same parameter?


#2

Yes, as explained in the instructions, attr_reader is to access the value and attr_writer is to modify the value, that's why you can have two of these for the same variable.

But you can also combine them in one: attr_accessor, which allows both behaviours.


#3

Hello,

the attr_accessor read and edits the attribute at the same time. Why is it necessary to read, when I overwrite/ edit the value anyway in the same step?

Even after googling the issue I don't really understand what is happening in Ruby in this line,

attr_reader :attributename
or: attr_writer/ attr_accessor

it happens within the class, the attribute gets read, okay but which instance is engaged here? Get the value saved somewhere in this step? It seems like an empty line of code for me, since I don't give the value of the attribute to anything here.

Thanks