-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6-3.rb
More file actions
47 lines (40 loc) · 1009 Bytes
/
6-3.rb
File metadata and controls
47 lines (40 loc) · 1009 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
class Bicycle
attr_reader :size, :style, :tape_color, :front_shock, :rear_shock
def initialize(args)
@style = args[:style]
@size = args[:size]
@tape_color = args[:tape_color]
@front_shock = args[:front_shock]
@rear_shock = args[:rear_shock]
end
# styleの確認は危険な道へ進む一歩
def spares
if style == :road
{
chain: '10-speed',
tire_size: '23', # milimeters
tape_color: tape_color,
}
else
{
chain: '10-speed',
tire_size: '23', # inches
tape_color: tape_color,
}
end
end
end
class MountainBike < Bicycle
attr_reader :front_shock, :rear_shock
def initialize(args)
@front_shock = args[:front_shock]
@rear_shock = args[:rear_shock]
super(args)
end
def spares
super.merge(rear_shock: rear_shock)
end
end
mountain_bike = MountainBike.new(size: 'S', front_shock: 'Manitou', rear_shock: 'Fox')
p mountain_bike.size
p mountain_bike.spares