You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains 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
In this exercise you're going to write some code to help you cook a brilliant lasagna from your favorite cooking book.
You have four tasks, all related to the time spent cooking the lasasgna.
1. Define the expected oven time in minutes
Define the Lasagna::EXPECTED_MINUTES_IN_OVEN constant that returns how many minutes the lasagna should be in the oven. According to the cooking book, the expected oven time in minutes is 40:
Lasagna::EXPECTED_MINUTES_IN_OVEN# => 40
2. Calculate the remaining oven time in minutes
Define the Lasagna#remaining_minutes_in_oven method that takes the actual minutes the lasagna has been in the oven as a parameter and returns how many minutes the lasagna still has to remain in the oven, based on the expected oven time in minutes from the previous task.
Define the Lasagna.preperation_time_in_minutes method that takes the number of layers you added to the lasagna as a parameter and returns how many minutes you spent preparing the lasagna, assuming each layer takes you 2 minutes to prepare.
Define the Lasagna#total_time_in_minutes method that takes two named parameters: the first parameter is the number of layers you added to the lasagna, and the second 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.
Ruby is a dynamic [object-oriented language]. Everything in Ruby is an [object].
There are two ways to assign objects to names in Ruby - assigning variables or constants. Variables always start with lower-case letters and use "snake case" for their formatting. A variable can be redefined to different objects over its lifetime. For example, my_first_variable can be defined and redefined many times using the = operator:
Constants, however, can only be assigned once. The must start with captial letters and are normally written in block capitals with words seperated by underscores. For example:
MY_FIRST_CONSTANT=10# Redefining not allowed# MY_FIRST_CONSTANT = "Some String"
Ruby is organised into classes. Classes are defined using the class keyword followed by the name of the class. Classes are initialized using the .new method.
# Define the classclassCalculator#...end# Create an instance of it and assign it to a variablemy_first_calc=Calculator.new
A function within a class is referred to as a method. Each method can have zero or more parameters. Objects are returned from methods using the return keyword. If no return value is specified, the final object in the method is returned instead. Methods can also have named parameters which are defined and called using the : syntax. Methods are invoked using . syntax.
This file contains 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
This file contains 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