RubyIrbSettings

November 13, 2006
Stumbled across this recently in the blogosphere (via the WaTiR mailing list, I believe). Probably not news to many Rubites, but it makes me very happy. Some old versions of 1.8 (or maybe 1.6) somehow had the save history part ‘just working’ (I think taking advantage of the inherent history in the Windows console stuffs) - but it hasn't just worked for quite sometime. (I did knock my head against the wall for sometime on the save history portion before I realized it required 1.8.4, and I was still back on 1.8.2).

Put the following in the .irbrc file (%USERPROFILE%/.irbrc for Windows), and you get code completion and saved history of commands:

require 'irb/completion'
ARGV.concat [ "--readline", "--prompt-mode", "simple" ]

# requires Ruby 1.8.4
require 'irb/ext/save-history'
IRB.conf[:SAVE_HISTORY] = 100
IRB.conf[:EVAL_HISTORY] = 100
IRB.conf[:HISTORY_FILE] = "#{ENV['USERPROFILE']}/.irb-save-history"


UPDATE: After some time, this stopped working on one of my Windows machines. FileMon showed my .irbrc file was never getting loaded, irb was only looking for it in the current directory. In trying to research why my Ruby 1.8.4 install irb wasn't looking for this file in my %USERPROFILE% folder, I didn't find a fix, but I did find a good workaround that worked for me:
An alternate approach is to create an environment variable called IRBRC and set it to the full path of the .irbrc file.

tags: ComputersAndTechnology