forked from skmetz/poodr2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3_45.rb
More file actions
42 lines (36 loc) · 701 Bytes
/
Copy path3_45.rb
File metadata and controls
42 lines (36 loc) · 701 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
# with keyword args
class Gear
attr_reader :chainring, :cog
def initialize(chainring:, cog:)
@chainring = chainring
@cog = cog
end
def gear_inches(diameter)
ratio * diameter
end
def ratio
chainring / cog.to_f
end
# ...
end
class Wheel
attr_reader :rim, :tire, :gear
def initialize(rim:, tire:, chainring:, cog:)
@rim = rim
@tire = tire
@gear = Gear.new(chainring: chainring, cog: cog)
end
def diameter
rim + (tire * 2)
end
def gear_inches
gear.gear_inches(diameter)
end
# ...
end
puts Wheel.new(
rim: 26,
tire: 1.5,
chainring: 52,
cog: 11).gear_inches
# => 137.0909090909091