Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

Hirb: An Easy-to-Use View Framework for irb

By Ric Roberts / June 28, 2009

hirb The Interactive Ruby Shell (irb) and the Rails console are great for interacting and experimenting with your ruby application code, but sometimes it's hard to visualize the output. Gabriel Horner has come to the rescue with Hirb: a 'mini view framework' for irb which is designed to improve the default output to make it more human-readable.

Hirb does this by formatting console output according to its type, and paging if there's more than a screenful to display. For example, Hirb will automatically display ActiveRecord model instances in a non-wrapping, table-like view.

irb>> Tag.last
| id  | created_at              | description |
| 907 | 2009-03-06 21:10:41 UTC | blah        |
1 row in set

There's also a helper provided which displays a collection of arrays or hashes as a tree. This might be useful for visualizing class inheritance trees, nested classes or relationships between ActiveRecord models (as this blog post describes).

In addition to the defaults you can specify your own reusable views, as the author explains in the documentation, leading you through an example of displaying hashes as YAML.

Hirb prints to the standard output by default, but you can configure it to write to anywhere you like, such as a log file.

The source code is on Github (or it can be installed as a gem), with documentation available on the author's site. Hirb users are invited to share any views they have written by forking the Github repository and adding them into the project structure.


  1. cldwalker says:

    Thanks for the mention! Glad others are finding Hirb useful.

  2. David Sousa says:

    I want to say thanks to RubyInside. Always bringing useful posts.

Other Posts to Enjoy

Twitter Mentions