June 2017
Beginner
330 pages
7h 30m
English
Now, what happens when we want to make one of these values optional? For example, what if we want to give a default value to the URL? To do that, we can update our initialize method with the following syntax:
def initialize (title, description, url = "google.com")
Now our program will have the same output even if we don't pass the url value while creating a new instance of the class. In this case, the output is unchanged when you have the following code:
api = ApiConnector.new("My title", "My cool description")
This is how you can define optional arguments in an initialize method.
Read now
Unlock full access