Arguments, Return Values and Encapsulation Flashcards
What is the value returned if no return keyword is specified?
The last expression evaluated.
What is the returned value if no explicit value if returned nor expression is evaluated?
Nil value is returned.
What is the returned value of puts function?
Nil.
How to differentiate a variable and a method with the same name?
We need to call the method with parenthesis.
What is the purpose of the * in a list of arguments?
It is to pass more arguments than actually declared in the method. Those extra arguments will be returned in an array.
What is Encapsulation in OOP?
Encapsulation means to wrap the data an methods inside the object.
What is Information Hiding and why is it important?
Information Hiding is a practice where the information (data) and the implementation (methods) of the object should be invisible to the outside world.
What is the “One way in one way out” principle?
This principle means that any change made to an argument inside a method won’t change the value of the variable outside. This has some exceptions like the use of methods with ! mark.
How do the methods with ! mark work?
These kind of methods modify the object itself instead of return a new one.
Why is it important to avoid modifications of arguments (objects) passed to a method?
Because these modifications could cause side effects in the variable passed as an argument to the method. For instance, if we modify the argument using a method with exclamation mark the variable outside (the one passed as an argument) will be modified too.