Created
October 14, 2012 05:55
-
-
Save sandbochs/3887536 to your computer and use it in GitHub Desktop.
FLEETS AND CARS
This file contains 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 Fleet | |
def initialize | |
@a_fleet = [] | |
end | |
def add_car(car) | |
if car.class.to_s != "Car" | |
puts "Not a car..." | |
end | |
@a_fleet << car | |
end | |
def get_car | |
@a_fleet.shift | |
end | |
def refuel_fleet | |
@a_fleet.each do |car| | |
car.refuel | |
end | |
end | |
end | |
class Car | |
attr_reader :gas_tank, :MAX_GALLONS | |
def initialize | |
@gas_tank = 0 | |
@MAX_GALLONS = 18 | |
end | |
def refuel | |
@gas_tank = @MAX_GALLONS | |
end | |
end | |
my_fleet = Fleet.new | |
my_car = Car.new | |
my_fleet.add_car(my_car) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment