Let’s build a class!

class ClassName def method_name(parameter) @class_variable = parameter end end
  1. First we tell Ruby that we want to construct our class ClassName. Don’t forget the end to end your class!
  2. Inside our ClassName is where we define our methods. Here we have method_name followed by (parameter), When we use this method it will look like this method_name("hello!")
  3. If our parameter above were “Hello!” it would be assigned to our variable @class_variable on the following line.
  4. Again, don’t forget to end your method_name!



First, create a class named Dog

Create a method initialize within your class Dog.

Allow your initialize method to accept two parameters, name and breed.

Inside your initialize method assign those two parameters to the variables @name and @breed respectively

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?