Skip to content

Instantly share code, notes, and snippets.

@sandbochs
Created October 14, 2012 05:55
Show Gist options
  • Save sandbochs/3887536 to your computer and use it in GitHub Desktop.
Save sandbochs/3887536 to your computer and use it in GitHub Desktop.
FLEETS AND CARS
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