ruby debugger config
Whenever you notice a strange behaviour in the code or unable to assert the strange behaviour via a test, it's helpful to launch the debugger and start inspecting the variables / try evaluating the piece of code. The REPL has so far been the best features offered by any good dynamic or functional language like ruby, haskell, clojure, python etc.
You could install ruby debugger for ruby 1.9 using the traditional gem command or adding it to the Gemfile depending on your environment.
gem install ruby-debug19
The debugger can then be invoked anywhere in the code by requiring the debugger.
require 'ruby-debug/debugger'
The debug console is pretty advanced in terms of functionality and can be used in the same way as gdb. However, more often you use the debugger, typing eval every time gets tedious. You can avoid this by typing in
set autoeval
By doing so, every single line of code you type in the console will be immediately evaluated in the context of the currently executing code.
Also, when the debugger launches, it gives the next line of code it's about to evaluate. In most cases, this should be fine but it helps to see few lines around the code. You can enable this by
set autolist
Once this is set, it will show the line surrounding the current code execution.
Or you can set this is the environment default by setting it up in .rdebugrc. This is how my .rdebugrc looks like this.
set autolist
set autoeval
set autoreload
For a full list of debug commands, look up the cheat sheet. Also check pivotal labs article on quickly setting up debugger for rails.














