Ruby has this handy and convenient way to share instance variables by using keys like
attr_accessor :var
attr_reader :var
attr_writer :var
Not all attributes of an object are meant to be directly set from outside the class. Having writers for all your instance variables is generally a sign of weak encapsulation and a warning that you're introducing too much coupling between your classes.
As a practical example: I wrote a design program where you put items inside containers. The item had attr_reader :container
, but it didn't make sense to offer a writer, since the only time the item's container should change is when it's placed in a new one, which also requires positioning information.