After jumping from link to link i came across hirb. What i found most useful about it is that it formats ActiveRecord descendants to a table. no more y for me!
Install:
sudo gem install hirb
@console:
>> require 'hirb'
>> []
>> Hirb.enable
>> true
To disable:
>> Hirb.disable
>> false
Sample output for ActiveRecord object
# Tag is a model class and descendant of ActiveRecord::Base >> Tag.last +-----+-------------------------+-------------+---------------+-----------+-----------+-------+ | id | created_at | description | name | namespace | predicate | value | +-----+-------------------------+-------------+---------------+-----------+-----------+-------+ | 907 | 2009-03-06 21:10:41 UTC | | gem:tags=yaml | gem | tags | yaml | +-----+-------------------------+-------------+---------------+-----------+-----------+-------+ 1 row in set>> tags = Tag.all :limit=>3, :order=>"id DESC" +-----+-------------------------+-------------+-------------------+-----------+-----------+----------+ | id | created_at | description | name | namespace | predicate | value | +-----+-------------------------+-------------+-------------------+-----------+-----------+----------+ | 907 | 2009-03-06 21:10:41 UTC | | gem:tags=yaml | gem | tags | yaml | | 906 | 2009-03-06 08:47:04 UTC | | gem:tags=nomonkey | gem | tags | nomonkey | | 905 | 2009-03-04 00:30:10 UTC | | article:tags=ruby | article | tags | ruby | +-----+-------------------------+-------------+-------------------+-----------+-----------+----------+ 3 rows in set
To make your own tables while in console, you could also use the table() and view() methods by
extend Hirb::Console
For example you only want to view cerain fields:
>> table tags, :fields=>[:id, :description, :name]
+-----+-------------+-------------------+ | id | description | name | +-----+-------------+-------------------+ | 907 | | gem:tags=yaml | | 906 | | gem:tags=nomonkey | | 905 | | article:tags=ruby | +-----+-------------+-------------------+ 3 rows in set
Or:
# Create a table of Dates comparing them with different formats. >> table [Date.today, Date.today.next_month], :fields=>[:to_s, :ld, :ajd, :amjd, :asctime] +------------+--------+-----------+-------+--------------------------+ | to_s | ld | ajd | amjd | asctime | +------------+--------+-----------+-------+--------------------------+ | 2009-03-11 | 155742 | 4909803/2 | 54901 | Wed Mar 11 00:00:00 2009 | | 2009-04-11 | 155773 | 4909865/2 | 54932 | Sat Apr 11 00:00:00 2009 | +------------+--------+-----------+-------+--------------------------+ 2 rows in set
I placed this in my .irbrc file:require 'hirb'
Hirb.enable
extend Hirb::Console Coolness! hirb's README says it all, go check it out.
