As a Ruby developer, you probably spend a reasonable amount of time in script/console or irb. What you may not have known was that you can extend and give your irb more functionality and make your life easier. I’d like to introduce you to ~/.irbrc.
Let’s add tab method completion as well, that’ll make life more simple.
require 'irb/completion'
One thing that had always annoyed me about irb is the lack of colour differentiating objects, strings, classes, etc. The Wirble gem solves this. I also installed utility_belt which has a bunch of extra features for your irb. (Don’t forget to install it via: sudo gem install wirble utility_belt)
# load rubygems, wirble and utility_belt
require 'rubygems'
require 'wirble'
require 'utility_belt'
# load wirble
Wirble.init
Wirble.colorize
utility_belt allows us to do a lot of great things, such as editing irb in Textmate, pastie-ing (OS X only), grep methods and classes, Google the last output (good for errors), only having to type x for quit
When debugging, I use ‘pp‘ (aka pretty_print) for examining my objects in Ruby. It’s annoying that I have to require it every time. Instead of having to constantly type in the require command, I have just added it to my irbrc file.
require 'pp'
You can also add methods to the file for later use . I have extended the Object class, to simulate the following: Post.methods - Class.methods
class Object
def non_class_methods
self.methods - Class.methods
end
end
I also added q as my exit command so i can exit by typing q and hitting return. utility_belt provides x for me, but I am more familiar with q.
alias q exit
You can see this file and all my other dot-files on Github.