a
Ruby
code posted
created at 05 May 19:46
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 25 26 27 28 29 30 31 32 33 34 |
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 def gear_inches #... a few lines of scary math foo = some_intermediate_result * diameter #... more lines of scary math end def wheel @wheel ||= Wheel.new(rim, tire) end |
640 Bytes in 3 ms with coderay