Working with Ruby
Hi, I am Jan. This is my old Ruby blog. I still post about Ruby, but I now do it on idiosyncratic-ruby.com. You should also install Irbtools to improve your IRB.

irbtools / Release the power of irb!

Equipped with some tools discussed at the germany.rb 2010 user group meetup, I’ve played around with my ~/.irbrc and put together a little meta gem for some useful irb tools (github)

Features

  • Colorized and output as comment by wirb and fancy_irb
  • Nice IRB prompt and IRB’s auto indention
  • Includes stdlib’s FileUtils: ls, cd, pwd, ln_s, rm, mkdir, touch, cat
  • Many debugging helpers: ap, q, o, c, y, Object#m, Object#d
    • apawesome_print
    • q – like p, but on one line
    • Object#m – ordered method list (takes integer parameter: level of nesting)
    • Objedt#d – puts the object, returns self (using tap)
  • “Magical” information constants: Info, OS, RubyVersion, RubyEngine
    • OS.windows?
    • RubyEngine.jruby?
    • RubyVersion.is.at_least? 1.9
  • Clipboard features: copy and paste
    • also available: copy_input and copy_output for session history
  • Call vim (or another supported editor) to edit a file, close it and it gets loaded into your current irb session, powered by interactive_editor
  • Another way of live loading into irb: sketches
  • Highlight a string with colorize('string') or a file with ray('path'), powered by coderay
  • Displays ActiveRecord database entries as tables with hirb
  • Restart irb with reset! or change the Ruby version with the use method and rvm!
  • Includes the current directory in the load path (was removed in 1.9.2 for security reasons, but is pretty annoying in IRB)
  • Shorter requiring like this: rq:mathn
  • And rerquiring with rrq
  • Try the included Object#ri helper, powered by ori!
  • Access to a lot of more commands with boson – call commands to get started

Screenshots

irbtools examples 1

irbtools examples 2

Setup

gem install irbtools

On Linux, you also need to sudo apt-get install xclip

On MacOS, you can install growl to use the g gem.

Usage

To use it, put the following in your ~/.irbrc file (this file is loaded every time you start an IRB):

require 'rubygems' unless defined? Gem # only needed in 1.8
require 'irbtools'

If it does not exists, just create a new one.

It’s is possible to modify, which libraries get loaded:

# no require 'irbtools'
require 'irbtools/configure'
# edit libraries using Irbtools.add_library and Irbtools.remove_library
Irbtools.start

RVM hint

You can add irbtools to ~/.rvm/gemsets/global and it will be installed automatically for new rubies.

By the way

Sometimes, you need a clean IRB without all the .irbrc libraries. In such a case, just start irb with the -f option and it will suppress loading the .irbrc.

Update

I’ve now released irbtools-more, which installs even more useful gems, which may not build out-of-the-box.

  • DrX object inspector: Object#see, requires tk
  • Better auto completion, using Bond

Github

Creative Commons License

rivsc | October 07, 2010

How to work with rails 3 ? I've added irbtools and irb_rocket in my Gemfile, but "rails c" crash :


no method in threshold: merge! for nil:NilClass
/usr/lib/ruby/gems/1.8/gems/guessmethod-0.2.1/lib/guessmethod.rb:10:in `unguessed_method_missing': undefined method `merge!' for nil:NilClass (NoMethodError)

J-_-L | October 07, 2010

Hi rivsc,
I will investigate this. As a workaround, you can do:
<code>require 'irbtools/configure'
Irbtools.libs -= %w[guessmethod]
Irbtools.init</code>

Lucas Efe | October 07, 2010

Hi, Rivse, the problem is not on guess method, but on irbtools.rb, where the IRB prompt is being set. I am having the same problem. I will investigate... :)

Lucas Efe | October 07, 2010

Sorry, rivse no, I meant janlelis.

J-_-L | October 07, 2010

Yep, sry, it's fixed with version 0.7.2

zigzo | October 07, 2010

Fantastic! This is my first shot at using a beautified IRB prompt and so far it's great! thank you!!

rivsc | October 08, 2010

Thanks ! It works with version 0.7.2, but hirb doesn't work ! (my hirb : the last version 0.3.4)

J-_-L | October 08, 2010

Hey rivsc, I am working on a fix. As a workaround, you can disable irb_rocket.

J-_-L | October 12, 2010

I've released 0.8.0. It fixes the hirb-irb_rocket problem, some guessmethod-rails bugs and more.

tianyicui | October 28, 2010

Just knew irbtools via thechangelog.com, it is fantastic! Thank you very much! But irb_rocket seems really buggy (at least in my 1.9.2 it hangs my irb A LOT) and I have to disable it. How about move it to `irbtools-more`?

J-_-L | October 31, 2010

I really like irb_rocket, but you are right, it can cause some headaches. I think, I'll just let it there and silence the warning if it is not installed. Thanks for the feedback :)