Created
September 24, 2018 06:55
-
-
Save harrisonmalone/685cdc1576868c5292b7ca130710e8cc to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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