Object-Oriented Programming II

Quick Review: Building a Class

Let's build a class!

class ClassName
  def method_name(parameter)
    @class_Variable = parameter
  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 MethodName followed by (parameter), When we use this method it will look like this MethodName("hello!")
  3. If our parameter above were "Hello!" it would be assigned to our variable @classVariable on the following line.
  4. Again, don't forget to end your MethodName!
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.