a

Ruby code posted
created at 05 May 18:53

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Gear
  attr_reader :chainring, :cog, :rim, :tire
  def initialize(chainring, cog, rim, tire)
    @chainring = chainring
    @cog       = cog
    @rim       = rim
    @tire      = tire
  end

  def gear_inches
    ratio * Wheel.new(rim, tire).diameter
  end

  def ratio
    chainring / cog.to_f
  end

end

# ~~~~~~

puts Gear.new(52, 11, 26, 1.5).gear_inches
puts Gear.new(52, 11, Wheel.new(26, 1.5)).gear_inches

445 Bytes in 2 ms with coderay