-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclasses_exercises2.rb
More file actions
58 lines (42 loc) · 843 Bytes
/
classes_exercises2.rb
File metadata and controls
58 lines (42 loc) · 843 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
58
class Robot
attr_accessor :name
def activate
puts "#{@name} is powering up"
end
#Hugo is powering up
def move (destination)
puts "#{@name} walks to #{destination}"
end
#Hugo walks to test dummy
end
#sample code
tank = TankBot.new
tank.name = "Hugo"
tank.weapon = "laser"
tank.activate
tank.move ("test dummy")
tank.attack
class TankBot < Robot
attr_accessor :weapon
def attack
puts "#{@name} fires #{@weapon}"
end
#Hugo fires laser
def move (destination)
puts "#{@name} rolls to #{destination}"
end
#Hugo rolls to test dummy
end
class SolarBot < Robot
def activate
puts "#{@name} deploys solar panel"
super
end
end
#Sunny deploys solar panel
#Sunny is powering up
#Sunny walks to tanning bed
sunny = SolarBot.new
sunny.name = "Sunny"
sunny.activate
sunny.move("tanning bed")