Object oriented programming 2 Flashcards

1
Q

Why are private methods used?

A

To make sure external users can’t accesses or harm your software.

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

What do private methods do?

A

They make sure that the method can’t be called from outside the class.

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

What is a public method?

A

A public method is a method that can be called from outside the class. All methods are public by default in ruby.

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

What is the attr_reader used for?

A

It is used for accessing a variable in a method/class

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

what is the attr_writer used for?

A

It’s used for changing the variable in the method/class

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

What is the attr_accessor used for?

A

It is used as bot a attr_reader and attr_writer.

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

What is an module in Ruby?

A

A module is like a class, but it can’t create instances or have subclasses.

Modules are good when using constants, because constants don’t change, but variables do.

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

How do you write a module?

A
module ModuleName
  # Bits 'n pieces
end
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you write constants in ruby?

A

You write them in ALL_CAPS

like PI

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

What is namespacing?

A

The main purpose of a module is to separate methods and constants into named spaces, and this is called namespacing.

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

What is the scope resolution operator?

A

It is used for telling ruby where to look for something.

Math : : PI means that Ruby should look for the PI inside the Math module.

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

What is require?

A

When the interpreter doesn’t have a module you need to bring it in with require. It basically runs another file.

require ‘module’

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

What is include?

A

The include method takes all the methods from one module and includes them in the current method.

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

What is mixin?

A

Mixin is when you blend additional behaviour from a module into a class. Meaning that we can customise a class whit out writing new code.

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

What is the extend keyword?

A

The extend keyword means that the class can use the methods as opposed to the instance of the class.

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