-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudent.rb
More file actions
28 lines (25 loc) · 762 Bytes
/
student.rb
File metadata and controls
28 lines (25 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
require './person'
class Student < Person
attr_reader :age, :name, :parent_permission, :classroom, :id
def initialize(age:, name:, parent_permission:, classroom: nil, id: nil)
classroom&.add_student(self) unless classroom&.includes?(self)
@id = id.nil? ? Random.rand(1..1000) : id
@age = age
@name = name
@parent_permission = parent_permission
@classroom = classroom
super(id: id, age: age, name: name, parent_permission: parent_permission)
end
def to_json(*_args)
JSON.dump({
id: @id,
age: @age,
name: @name,
parent_permission: @parent_permission,
classroom: @classroom
})
end
def play_hooky
"¯\(ツ)/¯"
end
end