Search code examples
ruby-on-railsrubyrubygemsruby-on-rails-plugins

Ruby Debugging Open Source Libraries


I would like to debug and possibly contribute to some open source gems but am fairly new to Ruby and Rails. What is the best way to go in and start setting breakpoints, etc?

Right now I just use ruby-debug for my own code and inspect variables mostly.


Solution

  • you need the ruby-debugger gem. Make sure you have have rubygems installed, then do

    gem install ruby-debug
    

    Then, add the line

    require 'ruby-debug'
    

    to your sourcecode to load the library, and add the keyword 'debugger' wherever you want to set a breakpoint. Now, whenever you call the code in question, it'll drop to the debugging console when it reaches the breakpoint - press h to see a list of options to see what you can do from there. Obviously, remember to remove your breakpoints and the require statement after you're done!