Skip to content

Instantly share code, notes, and snippets.

@mistermocha
Last active August 29, 2015 14:07
Show Gist options
  • Save mistermocha/5dc34f962bc55ce48109 to your computer and use it in GitHub Desktop.
Save mistermocha/5dc34f962bc55ce48109 to your computer and use it in GitHub Desktop.
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