-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate_method.rb
More file actions
57 lines (45 loc) · 798 Bytes
/
template_method.rb
File metadata and controls
57 lines (45 loc) · 798 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
54
55
56
57
class Drink
attr_accessor :name
def initialize(name)
@name = name
end
def make
get_cup
get_water
prepare
end
def get_cup
puts "Getting cup for a #{name}"
end
def get_water
puts "Boiling water for #{name}"
end
def prepare
raise 'Abstract method called'
end
end
class Tea < Drink
def prepare
puts 'Put tea bag into water'
puts 'Wait 5 minutes'
end
end
class Coffee < Drink
attr_accessor :type
def initialize(name, type)
super(name)
@type = type
end
def prepare
puts 'Put coffee into cup'
puts 'Pour hot water'
puts 'Wait'
end
end
puts 'PREPARING TEA'
tea = Tea.new('Darjeeling tea')
tea.make
puts '----------'
puts 'PREPARING COFFEE'
coffee = Coffee.new('Lavazza', 'natural arabica')
coffee.make