Locked lesson.
About this lesson
Let Ruby create your getters and setters automatically with attr_accessor.
Exercise files
Download this lesson’s related exercise files.
Understanding Attr_accessor.docx60.4 KB Understanding Attr_accessor - Solution.docx
59.3 KB
Quick reference
Understanding Attr_accessor
Attr_accessor allows you to create getters and setters automatically without typing them out.
When to use
Use them whenever you don't feel like typing out code for getters and setters!
Instructions
To use attr_accessor to create getters and setters:
attr_accessor :side_length
And just add that code to the top of your Class.
Hints & tips
- attr_reader :side_length # Creates a getter
- attr_writer :side_length # Creates a setter
- attr_accessor :side_length # Creates getter and setter
Lesson notes are only available for subscribers.