Skip to content

Commit

Permalink
add classroom association
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenkati committed Jun 21, 2023
1 parent 6cc1ed3 commit b6bba6a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions student.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require_relative 'person'

class Student < Person
attr_accessor :name, :classroom

def initialize(age, classroom, name: 'Unknown', parent_permission: true)
super(age, parent_permission: parent_permission, name: name)
@classroom = classroom
Expand All @@ -9,4 +11,10 @@ def initialize(age, classroom, name: 'Unknown', parent_permission: true)
def play_hooky
'¯\\(ツ)/¯'
end

def new_classroom=(classroom)
@classroom&.remove_student(self)
@classroom = classroom
classroom&.add_student(self)
end
end

0 comments on commit b6bba6a

Please sign in to comment.