From: Miguel Landaeta <nomadium@debian.org>
Date: Thu, 28 May 2015 20:05:48 -0300
Subject: Allow rdoc based tools to run if there are gem load errors
Forwarded: no

diff --git a/bin/rdoc b/bin/rdoc
index bddda40..6b3ba2c 100755
--- a/bin/rdoc
+++ b/bin/rdoc
@@ -19,5 +19,39 @@ if ARGV.first
   end
 end
 
-gem 'rdoc', version
-load Gem.bin_path('rdoc', 'rdoc', version)
+begin
+  gem 'rdoc', version
+  load Gem.bin_path('rdoc', 'rdoc', version)
+rescue NameError => e # --disable-gems
+  raise unless e.name == :gem
+rescue Gem::LoadError
+end
+
+require 'rdoc/rdoc'
+
+begin
+  r = RDoc::RDoc.new
+  r.document ARGV
+rescue Errno::ENOSPC
+  $stderr.puts 'Ran out of space creating documentation'
+  $stderr.puts
+  $stderr.puts 'Please free up some space and try again'
+rescue SystemExit
+  raise
+rescue Exception => e
+  if $DEBUG_RDOC then
+    $stderr.puts e.message
+    $stderr.puts "#{e.backtrace.join "\n\t"}"
+    $stderr.puts
+  elsif Interrupt === e then
+    $stderr.puts
+    $stderr.puts 'Interrupted'
+  else
+    $stderr.puts "uh-oh! RDoc had a problem:"
+    $stderr.puts e.message
+    $stderr.puts
+    $stderr.puts "run with --debug for full backtrace"
+  end
+
+  exit 1
+end
diff --git a/bin/ri b/bin/ri
index 2c0b3d5..f74c830 100755
--- a/bin/ri
+++ b/bin/ri
@@ -19,5 +19,14 @@ if ARGV.first
   end
 end
 
-gem 'rdoc', version
-load Gem.bin_path('rdoc', 'ri', version)
+begin
+  gem 'rdoc', version
+  load Gem.bin_path('rdoc', 'ri', version)
+rescue NameError => e # --disable-gems
+  raise unless e.name == :gem
+rescue Gem::LoadError
+end
+
+require 'rdoc/ri/driver'
+
+RDoc::RI::Driver.run ARGV
