Methods Flashcards

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

Define method

A

a named block of parameterized code associated with one or more objects

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

Define method invocation

A

specifies the method name, the object on which it is to be invoked (sometimes called the receiver), and zero or more argument values that are assigned to the named method parameters.

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

What is the value of a method invocation expression?

A

the last expression evaluated in the method

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

Methods are objects. T/F?

A

False

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

It is possible to create an object from a method. T/F?

A

True

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

How are methods different from blocks?

A

They are named and do not have to be invoked with an iterator method.

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

What is it called when an object represents a block?

A

a proc

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

What are the two kinds of proc objects?

A

lamdas and procs

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

What do we mean when we say a proc object is a closure?

A

retain access to the local variables that were in scope when they were defined, even when the proc or lambda is invoked from a different scope.

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

What keyword is used to define a keyword?

A

def

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

What value is returned from a method if no expression follows the return keyword?

A

nil

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

When must an explicit return value be used?

A

When more than one value needs to be returned.

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

What is a singleton method?

A

A method defined for just a single object.

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

What keyword is used to undefine a method?

A

undef

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

undefine can be used to undefine a method is a subclass but not the parent class. T/F?

A

true

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

What method can be used to undefine a method?

A

undef_method

17
Q

What punctuation marks can method names end with?

A

question mark, equal sign, or exclamation point

18
Q

What does an equal sign at the end of a method name indicate?

A

that it’s a setter method

19
Q

What does a question mark at the end of a method name often signify?

A

That it returns a boolean value.

20
Q

What does the Numeric method nonzero? return?

A

nil if it is zero or the number if it is not zero

21
Q

What does an exclamation point at the end of a method name usually signify?

A

That the object passed to the method will be modified by the method.

22
Q

Mutating methods that do not have a nonmutating variant do not typically have an exclamation point. T/F?

A

true

23
Q

What does the exit! method do?

A

aborts the program immediately without running any END blocks or shutdown hooks registered with at_exit.exit!

24
Q

exit! is not a mutator. T/F?

A

True