Created
June 11, 2014 17:25
-
-
Save jwo/5a1745eff72f56b9ab25 to your computer and use it in GitHub Desktop.
my day-3 homework (car)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Car | |
attr_reader :front_wheels | |
def initialize | |
wheel = Wheel.new | |
wheel2 = Wheel.new | |
wheel3 = Wheel.new | |
wheel4 = Wheel.new | |
@front_wheels = [wheel, wheel2] | |
@back_wheels = [wheel3, wheel4] | |
end | |
def turn(direction) | |
@front_wheels.each do |wheel| | |
wheel.turn(direction) | |
end | |
end | |
def wheels | |
@front_wheels + @back_wheels | |
end | |
def debug | |
puts @front_wheels.to_s | |
puts @back_wheels.to_s | |
end | |
end | |
class Wheel | |
attr_reader :direction | |
def initialize | |
@direction = 0 | |
end | |
def turn(direction) | |
@direction += direction | |
end | |
end | |
car = Car.new | |
car.turn(30) | |
directions = car.wheels.map do |wheel| | |
wheel.direction | |
end | |
puts car.front_wheels |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
pretty awful dude