Arguments, Return Values and Encapsulation Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is the value returned if no return keyword is specified?

A

The last expression evaluated.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the returned value if no explicit value if returned nor expression is evaluated?

A

Nil value is returned.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the returned value of puts function?

A

Nil.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to differentiate a variable and a method with the same name?

A

We need to call the method with parenthesis.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the purpose of the * in a list of arguments?

A

It is to pass more arguments than actually declared in the method. Those extra arguments will be returned in an array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is Encapsulation in OOP?

A

Encapsulation means to wrap the data an methods inside the object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is Information Hiding and why is it important?

A

Information Hiding is a practice where the information (data) and the implementation (methods) of the object should be invisible to the outside world.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the “One way in one way out” principle?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do the methods with ! mark work?

A

These kind of methods modify the object itself instead of return a new one.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Why is it important to avoid modifications of arguments (objects) passed to a method?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly