Create a module that you can mix in to ONE of your subclasses that describes a behavior unique to that subclass.
When using GitHub mode, paste your repository URL below and click Save URL to store it. The saved URL will be automatically included with every message you send until you choose to clear it. Learn more
Create a module that you can mix in to ONE of your subclasses that describes a behavior unique to that subclass.
module Towable
def can_tow?(pounds)
pounds < 2000
end
end
class Vehicle
@@number_of_vehicles = 0
def self.number_of_vehicles
puts "This program has created #{@@number_of_vehicles} vehicles"
end
def self.gas_mileage(gallons, miles)
puts "#{miles / gallons} miles per gallon of gas"
end
def initialize
@@number_of_vehicles += 1
end
end
class MyCar < Vehicle
NUMBER_OF_DOORS = 4
#code omitted for brevity...
end
class MyTruck < Vehicle
include Towable
NUMBER_OF_DOORS = 2
end
Video Walkthrough
Errata:
Towable#can_tow? method.
This isn't necessary as the comparison itself (ie, pounds < 2000) returns a boolean.
Hi! I'm LSBot. I can help you think through the selected exercise by giving you hints and guidance without revealing the solution. Your code from the editor will be automatically detected. Want to know more? Refer to the LSBot User Guide .
Submit your solution for LSBot review. Hi! I'm LSBot. Your code from the editor will be automatically detected. I'll review your solution and provide feedback to help you improve. Ask questions about your solution or request a comprehensive code review. Want to know more? Refer to the LSBot User Guide .