w1d3 Revisions Flashcards

0
Q

What does the following code do:

begin
  Code.parse('str')
rescue
  puts "Error parsing code!"
  retry
end
A

It sets up a condition to catch an exception raised by Code.parse, and tries again.

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

Within a class, what does the following code do:

def
pegs[i]
end

A

Creates a special kid of instance method where #[num] will retrieve the value of pegs[i]

Effectively, it creates the following shorthand:

instance_name[i]

Which stands in for:

instance_name.pegs[i]

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

Explain the following code:

Mastermind::Game.new.play

A

Retrieves the Game class from the Mastermind module, then runs the new method, and then the play method on the object which new returns

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

T/F: begin-rescue-retry-end can be used to respond to a specific type of error.

A

T; the specific error is passed to ‘rescue’

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