Skip to content

Instantly share code, notes, and snippets.

@harrisonmalone
Created September 24, 2018 06:55
Show Gist options
  • Save harrisonmalone/685cdc1576868c5292b7ca130710e8cc to your computer and use it in GitHub Desktop.
Save harrisonmalone/685cdc1576868c5292b7ca130710e8cc to your computer and use it in GitHub Desktop.
class Car
attr_reader :brand
@@cars = 0
def self.number_of_cars
return @@cars
end
def initialize(brand)
@brand = brand
@@cars += 1
end
def print_brand
puts "The car brand is: #{@brand}"
end
end
cars = [
Car.new('BMW'),
Car.new('FORD'),
Car.new('TESLA'),
Car.new('LAMBORGHINI')
]
american_cars = [
Car.new('FORD'),
Car.new('DODGE'),
Car.new('TESLA'),
Car.new('CHRYSLER')
]
def print_car_brands(cars)
puts "-" * 50
cars.each do |car|
car.print_brand
end
end
print_car_brands(cars)
print_car_brands(american_cars)
p Car.number_of_cars
bmw = Car.new('BMW')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment