-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex44d.rb
43 lines (33 loc) · 865 Bytes
/
ex44d.rb
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
#All three examples of inheritance interacting in the one file.
class Parent
def override()
puts "PARENT override()"
end
def implicit()
puts "PARENT implicit()"
end
def altered()
puts "PARENT altered()"
end
end
class Child < Parent
def override()
puts "CHILD override()"
end
def altered()
puts "CHILD, BEFORE PARENT altered()"
super()
puts "CHILD, AFTER PARENT altered()"
end
end
dad = Parent.new() #dad is an instance of parent
son = Child.new() #son is an instance of child
dad.implicit() #returns "PARENT implicit()"
son.implicit() #returns "PARENT implicit()"
dad.override() #returns "PARENT override()"
son.override() #returns "CHILD override()"
dad.altered() #returns "PARENT altered()"
son.altered() #returns:
# "CHILD, BEFORE PARENT altered()"
# "PARENT altered()"
# "CHILD, AFTER PARENT altered()"