Skip to content

Instantly share code, notes, and snippets.

@jwo
Created June 11, 2014 17:25
Show Gist options
  • Save jwo/5a1745eff72f56b9ab25 to your computer and use it in GitHub Desktop.
Save jwo/5a1745eff72f56b9ab25 to your computer and use it in GitHub Desktop.
my day-3 homework (car)
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
@jwo
Copy link
Author

jwo commented Jun 11, 2014

pretty awful dude

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment