Skip to content

Instantly share code, notes, and snippets.

@leoaretakis
Created July 24, 2013 09:49
Show Gist options
  • Select an option

  • Save leoaretakis/6069293 to your computer and use it in GitHub Desktop.

Select an option

Save leoaretakis/6069293 to your computer and use it in GitHub Desktop.
Exercise proposed by Leandro
class Car
attr_accessor :color
attr_accessor :model
def engage_gear(gear)
@gear = 1
@gear = gear if gear
end
def accelerate
@status = "stopped"
@status = 'moving' if @gear > 0
end
def reduce
engage_gear(@gear - 1) if @gear > 0
end
def stop
reduce while @gear > 0
@status = "stopped"
end
def start
engage_gear(nil)
accelerate
end
def in_gear?
@gear > 0
end
def stopped?
@status == 'stopped'
end
def in_movement?
@status == "moving"
end
end
cars = Array.new
(1..10).each { |n| cars << Car.new }
puts "Total of cars is #{cars.length}!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment