class Lasagna
EXPECTED_MINUTES_IN_OVEN = 40
def remaining_minutes_in_oven(actual_minutes_in_oven)
return EXPECTED_MINUTES_IN_OVEN - actual_minutes_in_oven
raise 'Please implement the Lasagna#remaining_minutes_in_oven method'
end
def preparation_time_in_minutes(layers)
return layers * 2
raise 'Please implement the Lasagna#preparation_time_in_minutes method'
end
def total_time_in_minutes(number_of_layers:, actual_minutes_in_oven:)
x = number_of_layers * 2
return actual_minutes_in_oven + x
raise 'Please implement the Lasagna#total_time_in_minutes method'
end
end
Constants are used in order to create values that never change, this is similar to variables, but constants can be useful especially with communicating how does your code work
TASK 4
Define the Lasagna#total_time_in_minutes method that takes two named parameters: the number_of_layers parameter is the number of layers you added to the lasagna, and the actual_minutes_in_oven parameter is the number of minutes the lasagna has been in the oven. The function should return how many minutes in total you've worked on cooking the lasagna, which is the sum of the preparation time in minutes, and the time in minutes the lasagna has spent in the oven at the moment.
The reason why the last test didn't work:
- You didn't define number_of_layers which is only prevalent to the 3rd def. You need to define it and make it the same code as layers class
Taken from community answers:
class Lasagna
EXPECTED_MINUTES_IN_OVEN = 40
PREPARE_MINUTES_PER_LAYER = 2
def remaining_minutes_in_oven(actual_minutes_in_oven)
EXPECTED_MINUTES_IN_OVEN - actual_minutes_in_oven
end
def preparation_time_in_minutes(layers)
PREPARE_MINUTES_PER_LAYER * layers
end
def total_time_in_minutes(number_of_layers:, actual_minutes_in_oven:)
preparation_time_in_minutes(number_of_layers) + actual_minutes_in_oven
end
end
PREPARE_MINUTES_PER_LAYER is better because it gives it a unique and constant value
Top comments (0)