Recovery from request / load failure in ruby

I recently discovered the Hanna RDoc template , and I like it a lot more than the default. I want to use it in my project, but I also do not want my project to require it.

The only change I had to make to my Rakefile to get the hanna template to work was to change

require 'rake/rdoctask'

to

require 'hanna/rdoctask'

Is there any way to try to request and commit / repair the error? I noticed the download and demanded to return boolean to irb, so I thought maybe I could do this:

unless require 'hanna/rdoctask'
  require 'rake/rdoctask'
end

Unfortunately, the rake was canceled as soon as the request failed. Then I tried:

begin
  require 'hanna/rdoctask'
rescue
  require 'rake/rdoctask'
end

but that didn't work either.

Is there a way to accomplish what I'm trying to do here?

+5
2

.

require 'rubygems'
begin
  require 'hanna/rdoctask'
rescue LoadError
  puts 'Hanna rdoc unavailable, falling back to rake'
  require 'rake/rdoctask'
end

, Ruby 1.8.7p248 "", " ". , , ? , "rake/rdoctask".

+4

irb

require , : it true, , false, , , .

LoadError.

+3

All Articles