puts “is this working”…

Countless hours spent spaghetti coding to work out your bugs, unexpected inputs, and flat out utter application inferno… Let’s face it debugging is something you’re going to have to be doing for the rest of your life as a programmer. The sooner you learn the tools that help you find the bugs in your code, the better off you’ll be in the long run. lucky for Rubyist there are many fancy debugging tools at our disposal. As programmers, we often have to mentally run code. We need to imagine how certain lines of code will behave given certain inputs. This can be daunting even for experienced devs, for beginners even more so. For starters we will go over Pry or binding.pry and why it’s an invaluable tool for jr and experienced devs alike.

Pry Cheat Sheet

Command Line

  • pry -r ./config/environment.rb - load your rails into a pry session
  • ls <Object> -- Show all of the available methods that can be called by an object
  • _ -- Last eval
  • ? <Object> -- Shows more information (doc) about an object, or method
  • _file_ -- Represent the last file Pry touched
  • wtf? -- Print the stack trace, same as _ex_.backtrace
  • $ -- Show source, shortcut for show-source
  • edit Class -- Open file in $EDITOR
  • edit Class#instance_method -- Open file in $EDITOR
  • <ctrl+r> -- Search history
  • _out_ -- Array of all outputs values, also _in_
  • cd <var> -- Step into an object, change the value of self
  • cd .. -- Take out of a level
  • binding.pry -- Breakpoint
  • edit --ex -- Edit the file where the last exception was thrown
  • .<Shell> -- Runs the command
  • whereami -- Print the context where the debugger is stopped
  • whereami 20 -- Print the context 20 lines where the debugger is stopped
  • ; -- Would mute the return output by Ruby
  • play -l -- Execute the line in the current debugging context


  • next -- execute next line
  • step -- step into next function call
  • continue -- continue through stack


  • rescue rspec -- break on exception in rspec
  • rescue rails server -- break on exception in rails server
  • try-again -- run last failing spec, reloads the file not the enviornment

Byebug Gem

gem install byebugdef some_methodsome code  

byebug # write it in your code and run the method or program
some other code
  • Breaking: Pausing the program at some event or specified instruction, to examine the current state.
  • Evaluating: Basic REPL functionality, although pry does a better job at that.
  • Tracking: Keeping track of the different values of your variables or the different lines executed by your program.
  • s => this will step into the next stack of code. Which means this will step the next function to be ran.
  • c => this continues the program until it either concludes or it reaches another breakpoint.
  • l => this outputs the source code that is currently being ran.
  • q => this will quit the ByeBug and return back to the program.
  • irb => this will put you into an interactive ruby session.
  • save => this will save your ByeBug history either with a specified file name inside of an argument, or with a default .byebug_save file name.
  • f => this shows the information for the current execution stack. It can also take in an integer as an argument to see what will be executing next.
  • hist => this will show you all of the history and persists through all of your debugging sessions.

unexpected end of input