Object-Oriented Programming I

What's in a @name?

All right! Just one more step before we can create a person from our Person class: we have to make sure each person has a @name.

In Ruby, we use @ before a variable to signify that it's an instance variable. This means that the variable is attached to the instance of the class.

class Car
  def initialize(make, model) 
    @make = make
    @model = model

kitt = Car.new("Pontiac", "Trans Am")

The code in the example above creates an instance, kitt, of the class Car. kitt has his own @make ("Pontiac") and @model ("Trans Am"). Those variables belong to the kitt instance, which is why they're called instance variables.

We'll cover other kinds of variables (like those attached to entire classes!) in the next few exercises.

Community Forums
Get help and ask questions in the Codecademy Forums
Report a Bug
If you see a bug or any other issue with this page, please report it here.