Perfect! Now that we think of it, though, we could have a whole bunch of users creating files every which where, and we don’t have a way of getting to our @@users class variable! We’ll need to create a method to reach it.

Because @@users is a class variable, we’ll use a class method to grab it. Most of the methods you’ve seen so far are instance methods—they work on a particular instance/object, such as “matz” or “blixy”. A class method belongs to the class itself, and for that reason, it’s prefixed with the class name.

class Machine def Machine.hello puts "Hello from the machine!" end end

There’s a shortcut for this, which we’ll learn in a later lesson.



Add a new class method to your Computer class called Computer.get_users. It should have no parameters.

Your new Computer.get_users method should return the @@users class variable.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?