Bird
0
0

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📝 Application Q15 of 15
Ruby - Ecosystem and Best Practices
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?
AUse <code>puts</code> statements to print all numbers
BInsert <code>byebug</code> at the start of the method without any condition
CInsert <code>binding.pry</code> inside the loop with a condition to pause only if the number is negative
DRun the program without breakpoints and guess the error
Step-by-Step Solution
Solution:
  1. Step 1: Understand conditional breakpoints

    Using binding.pry with a condition lets you pause only when needed, saving time.
  2. Step 2: Compare other options

    Using byebug without condition pauses every time, puts is less interactive, guessing is ineffective.
  3. Final Answer:

    Insert binding.pry inside the loop with a condition to pause only if the number is negative -> Option C
  4. Quick Check:

    Conditional breakpoint with binding.pry = A [OK]
Quick Trick: 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

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes