Back to Setup Page

Class Syntax

We’ve talked at a high level about classes, instances and attributes, and you may be starting to wonder what this will look like in code!

Explore Class Syntax

While this may feel uncomfortable at first, research shows this is one of the most effective ways to learn. Instead of your instructor typing code and explaining every character, you are going to read some Ruby code that's already been written. You will likely have some questions about what X or Y is doing, and you'll also likely be able to make some deductions about what other pieces are doing. We will talk through it all after you've had a chance to push your brain and make some connections on your own.

Look at the code in this repl.it and think through the guiding questions:

  • What is the name of the class?
  • How many instances are being made?
  • What is the attribute?
  • Can you make another instance?

As a class, let’s discuss what you probably found and maybe had questions about. We can diagram on the iPad and/or look at the live code!

Write a New Class

In the previous section, you identified an object in your home and wrote a list of instances and attributes.

In a repl.it file, write the Ruby code that would represent that class and instances. Don't forget to print out the instances!

Connection to Apps we Use

Now that you’ve seen how this “factory” concept can be used in code, you may be wondering about how this code concept is used within apps we use every day.

We won’t get all the way there in illustrating it today, but, we can look at Instagram for a moment to talk through where we see some use of classes and instances.

Instagram screenshot with annotations for user profile class and post class.

Next: Generating Valentine Messages