Can IRB look good?

  • Tips
  • June 30, 2009

MagMyPic.com - Step 1_ Select a Magazine Cover

Professional Rails developers know that ’script/console’ is an essential tool for testing and debugging applications. However, it can be tricky to read the output of large Objects such as a query result set. Here is an example of what we typically see in an IRB result set:

Default-1

To get around this, for the most part we learn little tricks like this:

print MODEL.all.to_xml

Doing the above will give you a more eye friendly xml formatted version of the contents of your Object. This works decently granted you are not overriding the “to_xml” method and serving just a few of the Object attributes. There are other time consuming ways(but sometime necessary) methods of print out debug information. One way is to write a for loop, using “puts” statements, or perhaps write a method in IRB. There is a better way.

Hirb was develop to help soften this pain. It will pretty print ActiveRecord results sets in such a way as you my see in the Mysql console.

Installation
sudo gem install cldwalker-hirb --source http://gems.github.com

Quick Start with Rails

Its easy to try hirb out with rails by doing the following:

Setup Irb
bash> script/console
Loading local environment (Rails 2.3.2)
irb>> require 'hirb'
=> []
irb>> Hirb.enable
=> nil

Usage
MODEL.all

root@clickhere14_~ — ruby — 147×41-1

Enjoy!

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • del.icio.us
  • Google
  • StumbleUpon
  • Technorati
  • description
  • Facebook
  • Reddit
  • Slashdot
  • TwitThis

This post was written by .

More Posts by   Visit 's Website

Leave a Reply