The pry gem allows you to pause your Ruby program and open an interactive console to inspect variables, test code, and understand program flow.
Click to reveal answer
beginner
How do you start a debugging session using byebug in Ruby?
Insert the line byebug in your Ruby code where you want to pause execution. When the program runs and reaches this line, it opens a debugging console.
Click to reveal answer
beginner
What command in pry lets you continue program execution after pausing?
Use the command continue or exit in the pry console to resume running the program after inspection.
Click to reveal answer
intermediate
Name one advantage of using byebug over simple puts debugging.
byebug lets you step through code line-by-line, inspect variables at any point, and control execution flow, which puts cannot do.
Click to reveal answer
beginner
How do you install pry and byebug gems for debugging?
Add gem 'pry' and gem 'byebug' to your Gemfile and run bundle install, or install directly with gem install pry byebug.
Click to reveal answer
Which command starts an interactive debugging session with byebug?
AInsert <code>byebug</code> in the code
BRun <code>ruby debug</code>
CUse <code>pry.start</code>
DCall <code>debugger()</code>
✗ Incorrect
You start byebug debugging by inserting the line byebug in your Ruby code.
What does the pry gem provide?
AA tool to automatically fix bugs
BAn interactive console to inspect and test code
CA syntax checker
DA code formatter
✗ Incorrect
pry opens an interactive console during program execution for inspection and testing.
Which command in pry resumes program execution after pausing?
Abreak
Bpause
Cstop
Dexit
✗ Incorrect
Typing exit in the pry console continues running the program.
What is a key benefit of using byebug instead of puts for debugging?
ARun code faster
BAutomatically fix errors
CStep through code line-by-line
DHide errors from users
✗ Incorrect
byebug lets you pause and step through code, unlike puts which only prints output.
How do you install pry and byebug gems?
AAdd to Gemfile and run bundle install
BUse <code>npm install</code>
CDownload from Ruby website
DNo installation needed
✗ Incorrect
You add the gems to your Gemfile and run bundle install to install.
Explain how you would use pry to debug a Ruby program.
Think about where to put the pause and what happens next.
You got /5 concepts.
Describe the steps to start a debugging session with byebug and how to control execution.
Focus on how to pause and move through code.
You got /5 concepts.
Practice
(1/5)
1. What is the main purpose of using binding.pry or byebug in Ruby code?
easy
A. To pause the program and inspect variables at a specific point
B. To speed up the execution of the program
C. To automatically fix syntax errors
D. To compile Ruby code into machine code
Solution
Step 1: Understand the role of debugging tools
Both binding.pry and byebug are used to pause program execution.
Step 2: Inspect variables and program state
When paused, you can check variable values and program flow to find issues.
Final Answer:
To pause the program and inspect variables at a specific point -> Option A
Quick Check:
Debugging tools pause and inspect = A [OK]
Hint: They pause code to check variables and flow [OK]
Common Mistakes:
Thinking they speed up code
Believing they fix errors automatically
Confusing with code compilation
2. Which of the following is the correct way to insert a breakpoint using Pry in Ruby code?
easy
A. debug.pry
B. breakpoint.pry
C. pry.binding
D. binding.pry
Solution
Step 1: Recall Pry syntax for breakpoints
The correct syntax to pause execution with Pry is binding.pry.
Step 2: Check other options for correctness
Other options like breakpoint.pry, pry.binding, and debug.pry are invalid method calls.
Final Answer:
binding.pry -> Option D
Quick Check:
Correct Pry breakpoint syntax = D [OK]
Hint: Use exactly 'binding.pry' to pause with Pry [OK]
Common Mistakes:
Swapping method and object order
Using non-existent methods
Forgetting to require 'pry'
3. What will be the output when running this Ruby code with byebug inserted?
def add(a, b)
byebug
a + b
end
puts add(2, 3)
medium
A. 5
B. byebug error
C. nil
D. SyntaxError
Solution
Step 1: Understand what byebug does
It pauses execution allowing inspection but does not change the return value.
Step 2: Trace the function call and output
The method add(2, 3) returns 5, which is printed by puts.
Final Answer:
5 -> Option A
Quick Check:
byebug pauses but output is 5 [OK]
Hint: byebug pauses but returns normal output [OK]
Common Mistakes:
Expecting byebug to change output
Thinking byebug causes errors
Confusing pause with program stop
4. You inserted binding.pry in your Ruby code, but when you run it, the program does not pause. What is the most likely reason?
medium
A. You used byebug instead of binding.pry
B. You forgot to require the 'pry' gem in your code
C. The Ruby version does not support debugging
D. You placed binding.pry after the return statement
Solution
Step 1: Check if 'pry' gem is loaded
Without require 'pry', binding.pry is undefined and won't pause.
Step 2: Verify placement and usage
Using binding.pry correctly requires the gem loaded; placing after return stops execution before breakpoint.
Final Answer:
You forgot to require the 'pry' gem in your code -> Option B
Quick Check:
Missing require 'pry' stops pause [OK]
Hint: Always require 'pry' before using binding.pry [OK]
Common Mistakes:
Not requiring the gem
Placing breakpoint after return
Confusing pry with byebug usage
5. You want to debug a method that processes a list of numbers and stops only when a number is negative. Which debugging tool and approach is best to use?
hard
A. Use puts statements to print all numbers
B. Insert byebug at the start of the method without any condition
C. Insert binding.pry inside the loop with a condition to pause only if the number is negative
D. Run the program without breakpoints and guess the error
Solution
Step 1: Understand conditional breakpoints
Using binding.pry with a condition lets you pause only when needed, saving time.
Step 2: Compare other options
Using byebug without condition pauses every time, puts is less interactive, guessing is ineffective.
Final Answer:
Insert binding.pry inside the loop with a condition to pause only if the number is negative -> Option C
Quick Check:
Conditional breakpoint with binding.pry = A [OK]
Hint: Use conditional binding.pry to pause only on negative numbers [OK]
Common Mistakes:
Pausing unconditionally causing many stops
Relying only on print statements
Ignoring debugging tools
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.