Locked lesson.
About this lesson
What is a class and how do we use them?
Exercise files
Download this lesson’s related exercise files.
Classes.docx60.3 KB Classes - Solution.docx
57.8 KB
Quick reference
Classes
Let's learn about classes!
When to use
Classes are used to group a bunch of methods together.
Instructions
To create a class called Square:
class Square
def initialize(side_length)
@side_length = side_length
end
end
Hints & tips
- Class names are uppercase
- The first method of a class is initialize
Lesson notes are only available for subscribers.