Implement a configurable Vehicle
class with an option to set
various attributes like engine, wheels, color, and interior, and
then display the configured vehicle's summary.
Within the Vehicle
class, define the following:
- A class method named
configure
that yields the vehicle object to a block for configuration.
- A class method named
interior
which handles the configuration for the vehicle's interior using an Interior
class and yields the interior object to a block for configuration.
- A class method the named
summarize_configuration
to generate the summary of the configured vehicle. It's important to note that the Interior
class requires its own summarize_configuration
method to return its interior configuration summary. This method should be called by the Vehicle
class's summarize_configuration
method. The final summary should look like this:
Note: The solution code defines a Vehicle
class with an embedded Interior
class, all in the same file. To enhance code organization, we can separate the
Interior
class into its own file called interior.rb
. In the main file, say
main_file.rb
, we can add a require_relative 'interior'
statement to include the
Interior
class. This way, the Vehicle
class can now utilize the Interior
class from the external file. The Interior
class will remain unchanged, maintaining its attributes and summarize_configuration
method. The revamped Vehicle
class will now focus solely on configuring a vehicle, including a class method configure
, an instance method interior
for initialization and a summarize_configuration
method for displaying the configured vehicle's summary.