Skip to content

Instantly share code, notes, and snippets.

@wjbuys
Created November 11, 2010 12:18
Show Gist options
  • Save wjbuys/672407 to your computer and use it in GitHub Desktop.
Save wjbuys/672407 to your computer and use it in GitHub Desktop.
IRB config to include some cool command-line tools
IRB.conf[:AUTO_INDENT] = true
IRB.conf[:USE_READLINE] = true
require 'rubygems'
def suggest(lib)
begin
require lib
yield if block_given?
rescue LoadError
puts "#{lib} not available."
end
end
# colored command output, persistent history
suggest 'wirble' do
Wirble.init
Wirble.colorize
end
# awesome_print
suggest 'ap'
# Nice tables for rails models
suggest 'hirb' do
Hirb.enable
def t(objects)
puts Hirb::Helpers::AutoTable.render(objects)
end
end
# lp command for method lookups
suggest 'looksee/shortcuts'
# Brilliant tab completion
suggest 'bond' do
Bond.start
end
gem "wirble"
gem "hirb"
gem "awesome_print"
gem "bond"
gem "looksee" # only works on ruby 1.8.x

Cool IRB tools

Install

Copy the .irbrc file into your homedir, and include the Gemfile snippet into any rails project you want the tools to be available in.

Gems used

Pretty much all of the ones from the irb section in the ruby-toolbox ;). Look there for more examples and docs.

Try these in IRB:

>> ap Post # works on ActiveRecord model classes
>> ap Post.all # and collections
>> t Post.all # for a nice readable table
>> po Post.first # show available methods
>> ap po Post.first # show available methods and where they come from
>> Post.create :desc<TAB> # autocomplete activerecord column names, everywhere
>> {:foo => 1, :bar => 2, :boing => 3}[:bo<TAB> # complete hash keys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment