-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecorator.rb
More file actions
54 lines (39 loc) · 689 Bytes
/
Decorator.rb
File metadata and controls
54 lines (39 loc) · 689 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
45
46
47
48
49
50
51
52
53
class ConcreteComponent
def initialize(list)
@list = list
end
def display(n)
@list[n-1]
end
def geta
@list.length
end
end
class Culc
def initialize(component)
@component = component
end
def add(n1,n2)
@component.display(n1)+@component.display(n2)
end
def sub(n1,n2)
@componet.display(n1)-@componet.display(n2)
end
end
class Script
def initialize(component)
@component = component
end
def stream
str = "#{'"'}"
@component.geta.times do |i|
str += @component.display(i+1).to_s
end
str += "#{'"'}"
end
end
comp = ConcreteComponent.new([1,2,3,4,5,6])
culc = Culc.new(comp)
script = Script.new(comp)
puts culc.add(1,3)
puts script.stream