OO in Ruby Flashcards

1
Q

In general, how do you declare a class and it’s methods?

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

In general, what are initializers and how do they work?

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

In general, how does more than one intializer work in Ruby?

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

What is raise in Ruby?

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

How does the array work with calling an intializer/constructor

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

In general, how would a class look with multiple arguments for the intializer?

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

In general, how do you use default values in Ruby initializers

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

How does overloading work in Ruby?

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

By default, what protection is data members and methods?

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

What is the shorthand for writing simple accessors and mutators?

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

how does to_s workin Ruby?

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

How do you make an instance in Ruby?

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

In general how do you invoke methods in Ruby?

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

How does yield work in Ruby?

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

How do you pass parameters to and from a code block to be used with yield?

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

What is the difference between (double-dots).. and (triple-dots)… in Ruby?

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

How do you pass multiple parameters in a code block in Ruby?

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

What would this code block output?

A

9

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

Explain how for loops are blocks

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

In the following code, what data members exist before the initializer is run

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

In general, how does ruby find the correct inherrited method?

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

With regard to inheritance, how do initializers work? How do you call the super initializer, when is it done by default, when is it not done?

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

For the following code, if we made super( ) the last statement in B’s initializer, what would the output be?

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

Explain in detail, what is happening the code below (shadowing/overriding)

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

In general how does Method refinement work in Ruby?

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

Java

class Node {

private ListItem theItem;

private Node link;

public void print(){

theItem.print();

}

Ruby

class Node

def initialize(initItem, initLink)

@theItem = initItem

@link = initLink

end

end

A
29
Q

In the attached code, How come if we get rid of ListItem (the hierarchy) and everything works the same way still?

A
30
Q

What is Duck Typing in Ruby?

A
31
Q

How does the attached code work?

A
32
Q

How do we address safety issues with Duck Typing?

A
33
Q

What do the following code return?

A
34
Q

How do you ask for the class of an instance or the superclass of a class?(e.g. if B is a subclass of A, and x is an instance of B)

A
35
Q

Why can’t you create an abstract class easily (as with Java)?

A
36
Q

What is example code to force an abstract class/self in Ruby?

A
37
Q

How do you define a class method in Ruby?

A
38
Q

In the attached code, what is super equivalent to?

A
39
Q

In gerneral how do we get an abstract method in Ruby?

A
40
Q

What do class data memebers begin with?

A
41
Q

In general how do you define a class method in Ruby?

A
42
Q

What is the output of the following code and why?

A
43
Q

In general, what happens when you define a class in Ruby? What can you think of every class being?

A
44
Q

How would you make a method apply at the class level of every class?

A
45
Q

In general how do you add a instance varible to Class Object

A
46
Q

What is the output of the following code and why?

A
47
Q

Much of the time you can forget about the fact that the class object exists… but when does it give itself away?

A
48
Q

what is example code to attach a method to a specific instance? Where would it be stored?

A
49
Q

How does private work with Ruby?

A
50
Q

In general, what are data members? And how are they inherited?

A
51
Q

What does private do to a method in Ruby?

A
52
Q

In general what is protected in Ruby?

A
53
Q

How do you make a class private in Ruby?

A
54
Q

In general how do Modules work in Ruby?

A
55
Q

What is the difference between classes and modules in Ruby?

A
56
Q

What is the specific code to use modules in Ruby?

A
57
Q

In what instances can a module method or inherited method name be overwritten by an existing method with the same name?

A
58
Q

What is the specific code to bring in a module form outside the soure file?

A
59
Q

When you use require “MyModule” or require “./MyModule”, how does the namespace work?

A
60
Q

What is the specific code for defining the GSTModule example and using it in your program?

A
61
Q

What’s a good practice when dealing with external modules?

A
62
Q

In general, how does the Ruby Module Comparable work?

A
63
Q

What is the difference between Java interfaces and Ruby modules?

A
64
Q

How do you read data from files in Ruby?

A
65
Q

In general how do you pase data from a file in Ruby?

A
66
Q

Specifically, how do you parse less structured files in Ruby?

A
67
Q

Specifically, how do you read command-line args in Ruby?

A
68
Q

What is Dynamic code generation and how does it work in Ruby?

A