Ruby - Attribute Readers and Writers


To create attributes, you can use attr_reader and attr_writer methods followed by a symbol (a name preceded by a colon):

attr_reader :description 
attr_writer :description 

You should add this code inside your class definition like this:

class Thing 
   attr_reader :description 
   attr_writer :description 
    # maybe some more methods here... 

Calling attr_reader with a symbol creates a get accessor named description for an instance variable (@description) with a name matching the symbol :description.

Calling attr_writer creates a set accessor for an instance variable.

Instance variables are considered to be the "attributes" of an object.

Related Topic