This post originated from an RSS feed registered with Ruby Buzz
by Daniel Berger.
Original Post: Avoiding Readline
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
One of the other issues that cropped up with building Ruby from source on Windows was the lack of support for the GNU/Readline library. It's basically impossible to compile from source using MS VC++. To top it all off, I don't even really know what the thing does other than some sort of terminal key binding thingy. I'd look at the documentation for the Ruby readline library...but there isn't any.
This sucked because I thought I had to have readline support in order to run the Rails console app, for example (which I find very handy). I considered rewriting readline using pure Ruby and the Win32::API library. More on that later.
But first, an aside. What's wrong with the following code?
begin
require 'readline'
rescue
# Skip readline support
end
See it? Remember, a rescue clause without an explicit error class defaults to StandardError. The problem is that this code raises a LoadError, which is not a subclass of StandardError. The result is that the failed require raises an error anyway.
I noticed that I was getting weird warnings about lack of readline support when I was doing gem installations. It seemed harmless, but it annoyed me. At first I thought it was some sort of dependency in rubygems, but it turned out to be a bug in rdoc 2.x caused by the code I showed above. Once fixed (and it's already fixed in SCM, thanks Eric) the warning went away.
Back to the Rails console app (i.e. script/console), which in turn uses irb. It was choking with an error about lack of readline support. I had assumed up to this point that you had to have readline support in order to use the Rails console. The error above, however, inspired me to inspect the irb source code to see just what the heck it really needed readline for.
And sure enough, it had the same bug that rdoc 2.x had - it wasn't checking for LoadError properly. Once I made that patch (submitted here), all worked well.
As for the pure Ruby version of readline, there's one out there called Inline. Well, sort of. It's pure Ruby but has a very different, though better, API. I've requested a "readline compatibility mode" so that it can be used as a stand-in replacement for the C extension. We'll see what comes of that.