I’m having difficulty understand the "self’ part in the solution of both student and course
How do we access a different class’s method without using subclass?
the solution is below and what exactly is self in student and course solutions?
attr_reader :courses, :first_name, :last_name
def initialize(first_name, last_name)
@first_name, @last_name = first_name.capitalize, last_name.capitalize
@courses = 
# ignore re-adding a course
return if courses.include?(course)
raise “course would cause conflict!” if has_conflict?(course)
self.courses << course course.students << self
load = Hash.new(0)
self.courses.each do |course|
load[course.department] += course.credits
self.courses.any? do |enrolled_course|
Solution for Course:
attr_reader :department, :name, :credits, :time_block, :days, :students
def initialize(name, department, credits, days=nil, time_block=nil)
@name, @department, @credits, @days, @time_block =
name, department, credits, days, time_block
@students = 
return false if self.time_block != course2.time_block
days.any? do |day| course2.days.include?(day) end
student.enroll(self) #What is this self?