-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinheritance_example.rb
More file actions
52 lines (38 loc) · 850 Bytes
/
Copy pathinheritance_example.rb
File metadata and controls
52 lines (38 loc) · 850 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
class Vehicle
def initialize
@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 Car < Vehicle
attr_writer :make, :model, :color
def initialize(input_options)
@make = input_options[:make]
@model = input_options[:model]
@color = input_options[:color]
end
def honk_horn
puts "Beeeeeeep!"
end
end
class Bike < Vehicle
def initialize(input_options)
super
end
def ring_bell
puts "Ring ring!"
end
end
car = Car.new(make: "Honda", model: "Civic", color: "Silver")
bike = Bike.new(make: "Schwinn", model: "Pontera", color: "Red")
p bike
p car