Help with Students and Courses in Class Interactions section

Hi all,

Im pretty stumped with how to move forward with the #add_student in Course class. Im stuck at the spec

  1. Course#add_student relies on Student#enroll

I keep getting the error
undefined method `enroll’ for Student:Class

I believe the spec is asking that I access the enroll method from the Student class but I’m not sure how to access it? Or is it asking something else and I’m missing it?

Here is my course code for reference

class Course
attr_accessor :name, :department, :credits, :students
def initialize(name, department, credit_num)
@name = name
@department = department
@credits = credit_num
@students = []

def add_student(student)
Student.enroll(student) #I believe this is where the issue lies
@students << student unless @students.include?(student)

You need to created an enroll method in your student class. This is in the student.rb file. Your add_student(student) method calls to the one in the student class. I hope that helps.

ah yes! I figured it out. Once I realized that the enroll method needed to run on the student class (the argument for add_student) then I could understand that the argument for enroll needs to be the course class (or self). Thanks for your help.