Last active
August 29, 2015 14:07
-
-
Save mistermocha/5dc34f962bc55ce48109 to your computer and use it in GitHub Desktop.
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 ParkingLot | |
def initialize(spaces) | |
# How do I access these on the instance? | |
@spaces = spaces | |
@cars = Array.new | |
end | |
def park(car) | |
if @cars.length < @spaces | |
@cars.push(car) | |
else | |
puts 'Lot Full' | |
end | |
end | |
end | |
class Car | |
def initialize(year, make, model) | |
@year = year | |
@make = make | |
@model = model | |
end | |
end | |
lot = ParkingLot.new 2 | |
lot.park(Car.new 2004, "Audi", "Quattro") | |
# This doesn't find @cars ... I get NoMethodError | |
puts lot.cars | |
lot.park(Car.new 1982, "VW", "Beetle") | |
puts lot.cars | |
lot.park(Car.new 2013, "Tesla", "S") | |
puts lot.cars |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment