-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvehicle.rb
55 lines (43 loc) · 815 Bytes
/
vehicle.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
class Vehicle
def initialize(hash)
@speed = 0
@direction = 'north'
end
def brake
@speed = 0
end
def accelerate
@speed += 10
end
def turn(new_direction)
@direction = new_direction
end
end
class Bike < Vehicle
attr_accessor :speed, :type, :weight
def initialize(hash)
super
@speed = hash[:speed]
@type = hash[:type]
@weight = hash[:weight]
end
def ring_bell
puts "Ring ring!"
end
end
class Car < Vehicle
attr_accessor :make, :model, :fuel
def initialize(hash)
super
@make = hash[:make]
@model = hash[:model]
@fuel = hash[:fuel]
end
def honk_horn
puts "Beeeeeeep!"
end
end
huffy = Bike.new({speed: 60,type: "fast",weight: 4000})
p huffy
herbie = Car.new({make: "toyota", model: "camry", fuel: 5})
p herbie