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