I have the following code:
class Cars
attr_accessor :car_make
attr_accessor :car_model
def initialize(make, model)
self.car_make = make
self.car_model = model
end
end
I would like to know if it is possible to implement a list_cars method
and call the method like so:
ford = Cars.new("Ford" ,"F-150")
honda = Cars.new("Honda", "CRV")
list_cars(ford, honda)
i.e., without necessarily calling it from an existing object. I tried this:
def list_cars(first_car, second_car)
puts "My father has two cars - a #{first_car.car_make} #{first_car.car_model} and a #{second_car.car_make} #{second_car.car_model}."
end
I realize that this code is missing something, but I don't know what that is.
list_carsis implemented outside classCarsright? Your code works for me.