Ruby Flashcards

1
Q

What are the three types of access levels in Ruby classes?

A

public, protected and private

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

How would you describe methods with private access level?

A

They can be accessed only in the current instance

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

What is the difference between each and map methods?

A

Each will iterate over the collection and return the original array. Map will return the modified array but it will not change the original one.

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

What is the result of

test

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

What is the result of a = false || 1

A

1

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

What is the ternary operator?

A

The ternary operator is a shorthand to a if clause.

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

How many types of variables are used in Ruby?

A

Four. Class, instance, global and local variables.

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

How do you cast variable type?

A

By using standard methods like to_i or to_s.

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

What is the result of a = true and false

A

a = true

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

How do you catch an exception in a method?

A

By wrapping the method body in begin and rescue clauses.

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

What does super method do?

A

Invokes the same method from the parent class.

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

What are the values that evaluate to false?

A

nil and false

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

How can a variable be made immutable?

A

By calling .freeze on it.

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

Is Ruby a statically typed or a dynamically typed language?

A

Dynamically typed.

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

What does self mean?

A

self references to the instance of the class or to the class itself.

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

What are the ways to invoke a method in Ruby?

A
  1. object.object_id
  2. object.send(:object_id)
  3. object.method(:object_id).call
17
Q

What’s the purpose of the garbage collector module in Ruby?

A

It frees up memory.

18
Q

What data types are available in Ruby?

A

Numbers
Booleans
Strings
Hashes
Arrays
Symbols