Debugging: binding.irb mastery
This course covers binding.irb, a line of Ruby that pauses a running method and opens an IRB prompt inside its scope. It compares this with puts debugging, where every question must be planned before a rerun. It explains how Kernel#binding captures the local scope and how Binding#irb opens a nested session. It shows inspecting locals, self and instance variables, resuming with continue or exit, and stepping with next through the debug gem. It ends by using binding.irb inside a Rails app through bin/rails runner.
What you'll learn
- ✓Why puts debugging forces you to plan every question before rerunning
- ✓How Kernel#binding and Binding#irb combine to open a prompt in a method's scope
- ✓Inspecting local variables, parameters, self and instance variables at a paused line
- ✓Resuming with continue or exit and stepping line by line with next
- ✓When to use binding.irb and when to use puts or logging
- ✓Using binding.irb with real models inside a Rails app through bin/rails runner
Beyond puts: live state inspection
A typical first debugging move: sprinkle puts calls through a method and rerun the whole program. You read what printed, decide it wasn't enough, add more puts calls, and rerun again.
Read the full lesson free →Curriculum
7 lessonsBeyond puts: live state inspection
Contrasts the puts rerun loop with binding.irb, which pauses a method and lets you query live state.
What binding.irb actually is
Explains that binding captures the local scope and Binding#irb opens a nested IRB session, with no Rails needed.
Locals, instance variables, and self, live
Shows that locals, parameters, self and instance variables all answer directly at the paused line.
next, continue, and stepping through
Covers continue and exit to resume execution, and next to step one line through the debug gem.
binding.irb vs. puts, side by side
Compares both approaches on one bug and explains when each fits: live investigation or unattended log output.
binding.irb inside a Rails app
Runs binding.irb through bin/rails runner, inspecting a real Catalog::Course record, and explains how it relates to reload!.
Putting it together: a live debugging session
Reviews every lesson against one paused line and compares binding.irb with a prompt started by bin/rails console.