Skip to content

Instantly share code, notes, and snippets.

@redstar504
Created November 22, 2012 21:46
Show Gist options
  • Save redstar504/4133042 to your computer and use it in GitHub Desktop.
Save redstar504/4133042 to your computer and use it in GitHub Desktop.
class Gear
attr_reader :chainring, :cog, :wheel
def initialize(chainring, cog, wheel=nil)
@chainring = chainring
@cog = cog
@wheel = Wheel.new(rim, tire)
end
def ratio
chainring / cog.to_f
end
def gear_inches
ratio * wheel.diameter
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
@wheel = Wheel.new(26, 1.5)
puts @wheel.circumference
puts Gear.new(52, 11, @wheel).gear_inches
puts Gear.new(52,11).ratio
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment