×

ruby · level 2 · unit 6 · lesson 1

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

A class is a recipe for making your own objects.

The class of a value tells you its kind, like String or Integer. Now you can make your own. Write class, a name in , the methods, then end. The class is a recipe: it does nothing until you use it.

Robot.new follows the recipe and hands you a new . Each object is an of its class, so calling Robot.new twice gives two separate robots. Every robot can use the methods written inside class Robot.

class Robot
  def greet
    "Beep! Hello."
  end
end
robo = Robot.new
puts robo.greet
p robo.class
puts Robot.new.greet

Class names start with a capital letter, which is how Ruby tells them apart from variables.