Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Tools for Troubleshooting Ruby

Tools for Troubleshooting Ruby


gem install debugger

In ~/.rdebugrc (You'll want to set these)

set autolist
set autoeval
set autoreload

In the location you want to debug, add the following line:

require 'debugger'; debugger; puts 'stay';

(The puts 'stay' is not technically required, but is useful if you are placing the debugger at the end of a block.)

While debugging, or in your IRB/Rails console, the following methods may be helpful:

object.method(:method_name).source_location # Ruby 1.9


gem install method_locator


An array of each defintion for that object's method.

object.methods_for(:method_name).each {|m| puts "#{m.source_location.first}:#{m.source_location.last}" }

The above prints the location of all method definitions for the given object's method.


An array of all of the classes and modules that compose the object.


Where is the gem I am using located on my machine $ bundle show <gemname>

Open the gem in my editor $ bundle open <gemname>


$ gem server or $ bundle exec gem server

Go to and view all of the gems, their locations and descriptions. If you installed the gems with RDoc, then you will also have access to the RDocs.


I hope you are using git.

Find when an error was introduced: $ git bisect

Have a test script that exits status 0 on success; and not 0 on failure

  • This could be a test script in your project or an external script

Mark one commit as good and another as bad, then run bisect.

  • It will point out exactly which commit broke your test script
  • As an aside, keep your git commits as small as possible, with each commit being a single concern.

A demo that you run from command line, walking through a handful of git commands, performing actions on a repo it creates:


You may appreciate formatted output in IRB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment