Thursday, February 23, 2017



Ruby tools for improved puts debugging, automatically displaying bonus useful information such as file, line number and source code.
Partially inspired by this blog post: (Credit to Tenderlove.)



Add the following to bundler's Gemfile.
gem 'puts_debuggerer'


Or manually install and require library.
gem install puts_debuggerer
require 'puts_debuggerer'


Simple invoke global pd method anywhere you'd like to see line number and source code with output. If the argument is a pure string, the print out is simplified by not showing duplicate source.
Quickly find printed lines by running a find (e.g. CTRL+F) for "pd " or ".inspect => "
Happy puts debugging!
Example Code:
# /Users/User/finance_calculator_app/pd_test.rb # line 1
bug = 'beattle'                                 # line 2
pd "Show me the source of the bug: #{bug}"      # line 3
pd 'What line number am I?'                     # line 4
Example Printout:
pd /Users/User/finance_calculator_app/pd_test.rb:3 "Show me the source of the bug: #{bug}".inspect => "Show me the source of the bug: beattle"
pd /Users/User/finance_calculator_app/pd_test.rb:4 "What line number am I?"

More at puts_debuggerer

No comments: