-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule_gear.rb
More file actions
56 lines (45 loc) · 964 Bytes
/
Copy pathmodule_gear.rb
File metadata and controls
56 lines (45 loc) · 964 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
require 'pry'
module SomeFramework
class Gear
attr_reader :chainring, :cog, :wheel
def initialize (args)
args = defaults.merge(args)
@chainring = args[:chainring]
@cog = args[:cog]
@wheel = args[:wheel]
end
def ratio
chainring / cog.to_f
end
def gear_inches
ratio * wheel.diameter
end
def defaults
{:chainring => 40, :cog => 18}
end
end
class Wheel
attr_reader :rim, :tire
def initialize(rim, tire)
@rim = rim
@tire = tire
end
def diameter
rim + (tire * 2)
end
def circumference
diameter * Math::PI
end
end
end
module GearWrapper
def self.gear(args)
SomeFramework::Gear.new(args[:chainring],
args[:cog],
args[:wheel])
end
end
GearWrapper.gear(
:chainring => 52,
:cog => 11,
:wheel => Wheel.new(26,1.5)).gear_inches