-
Notifications
You must be signed in to change notification settings - Fork 105
/
template.rb
62 lines (49 loc) · 1019 Bytes
/
template.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Define the skeleton of an algorithm in an operation, deferring some
# steps to subclasses. Template methods lets subclasses redefine certain
# steps of an algorithm without changing the algorithm's structure
class Hero
attr_reader :damage, :abilities
def initialize
@damage = damage_rating
@abilities = occupation_abilities
end
def greet
greeting = ["Hello"]
greeting << unique_greeting_line
greeting
end
def unique_greeting_line
raise "You must define unique_greeting_line"
end
def damage_rating
10
end
def occupation_abilities
[]
end
def attack
"Atack dealing #{damage} damage"
end
end
class Warrior < Hero
def damage_rating
15
end
def occupation_abilities
[:strike]
end
def unique_greeting_line
"Warrior is ready to fight!"
end
end
class Mage < Hero
def damage_rating
7
end
def occupation_abilities
[:magic_spell]
end
def unique_greeting_line
"Mage is ready to make powerful spells!"
end
end