-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathother_class.rb
More file actions
44 lines (35 loc) · 870 Bytes
/
other_class.rb
File metadata and controls
44 lines (35 loc) · 870 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
## --> This code doesn't use the name Parent, since there is not a
## parent-child is-a relationship.
## This is a has-a relationship, where Child has-a Other that it uses
## to get its work done.
class Other
def override()
puts "OTHER override()"
end
def implicit()
puts "OTHER implicit()"
end
def altered()
puts "OTHER altered()"
end
end
class Child
def initialize()
@other = Other.new() ## Create new instance of Other class
end
def implicit()
@other.implicit() ## Call implicit method with instance of Other
end
def override()
puts "CHILD override()"
end
def altered()
puts "CHILD, BEFORE OTHER altered()"
@other.altered()
puts "CHILD, AFTER OTHER altered()"
end
end
son = Child.new()
son.implicit()
son.override()
son.altered()