To set a value, there has to be a setter defined. To retrieve a value,
e.g.
puts obj.some_var_name
there has to be a getter defined. You can make ruby define both the
setter and getter for you by including the following in your class:
attr_accessor :some_var_name
That is equivalent to explicitly writing the getter and setter shown
above. Or, if you don’t want people to be able to set the value, you
can define
only the getter:
attr_reader :some_var_name
That is equivalent to defining the getter shown above. Similarly using
attr_writer in your class is equivalent to defining the setter shown
above.