Ruby Syntax Highlighting Within The Console With Wirble And The RVM
Wirble is an awesome gem that gives you ruby syntax highlighting from within the console. The problem is when you use RVM to manage your gemsets you need the wirble gem installed for all of your gemsets (or at least in the global gemset for each version of ruby).
A nice way to get around this issue is to check to see if the wirble gem is available when you enter irb and if it’s not then install it.
So how do you do that then? Well its pretty simple. When you load irb it will look or a .irbrc file located at ~/.irbrc and execute any code within that file.
require 'irb/completion'
require 'irb/ext/save-history'
require 'rubygems'
%x{gem install 'wirble' --no-ri --no-rdoc} unless Gem.available?('wirble')
Gem.refresh
require 'wirble'
Wirble.init
Wirble.colorize
colors = Wirble::Colorize.colors.merge({
:object_class => :purple,
:symbol => :purple,
:symbol_prefix => :purple
})
Wirble::Colorize.colors = colors
On the 4th line it just checks to see if wirble is installed, if it is not then it just installs it and on the 5th line refreshes your gems before requiring it.
Of course if you are not using the RVM this will work perfectly also.