-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9_classes.rb
More file actions
65 lines (54 loc) · 1.28 KB
/
9_classes.rb
File metadata and controls
65 lines (54 loc) · 1.28 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class Mammal
end
class Primate < Mammal
end
class Person < Primate
attr_accessor :first_name
attr_accessor :last_name
def full_name
return "#{first_name} #{last_name}"
end
end
class Instructor < Person
attr_accessor :role
end
class Student < Person
attr_accessor :grade
end
# Creating first individual instance of the Instructor class
person1 = Instructor.new
person1.first_name = "Raghu"
person1.last_name = "Betina"
person1.role = "Lecturer"
puts person1.inspect
# Creating second individual instance of the Instructor class
person2 = Instructor.new
person2.first_name = "Josh"
person2.last_name = "Elkin"
person2.role = "Teaching Assistant"
puts person2.inspect
# Creating first individual instance of the Student class
person3 = Student.new
person3.first_name = "Brian"
person3.last_name = "Smith"
person3.grade = "A+"
puts person3.inspect
# Creating second individual instance of the Student class
person4 = Student.new
person4.first_name = "Eric"
person4.last_name = "Snyder"
person4.grade = "A"
puts person4.inspect
puts person1.full_name
puts person1.role
puts person2.full_name
puts person2.role
puts person3.full_name
puts person3.grade
puts person4.full_name
puts person4.grade
# What would happen if I tried doing:
# person4.role
# What about:
# person1.grade
# Why?