diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-06-10 21:07:24 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-06-10 21:18:56 +0900 |
commit | 976c689ad478b8010b053aa270a28bd236b8380e (patch) | |
tree | fe9a6f494bcd87ab28dc89d0cf7cf3af352070e5 /lib | |
parent | 973fd18f11f5026024fc43e2848db030110bdaee (diff) |
irb: defer requiring rdoc to improve the start up time
Diffstat (limited to 'lib')
-rw-r--r-- | lib/irb/cmd/help.rb | 13 | ||||
-rw-r--r-- | lib/irb/completion.rb | 4 |
2 files changed, 10 insertions, 7 deletions
diff --git a/lib/irb/cmd/help.rb b/lib/irb/cmd/help.rb index 71590ee844..10ec13475a 100644 --- a/lib/irb/cmd/help.rb +++ b/lib/irb/cmd/help.rb @@ -9,17 +9,18 @@ # # -require 'rdoc/ri/driver' - require_relative "nop" # :stopdoc: module IRB module ExtendCommand class Help < Nop - begin - Ri = RDoc::RI::Driver.new - rescue SystemExit + def execute(*names) + require 'rdoc/ri/driver' + IRB::ExtendCommand::Help.const_set(:Ri, RDoc::RI::Driver.new) + rescue LoadError, SystemExit + IRB::ExtendCommand::Help.remove_method(:execute) + # raise NoMethodError in ensure else def execute(*names) if names.empty? @@ -35,6 +36,8 @@ module IRB end nil end + ensure + execute(*names) end end end diff --git a/lib/irb/completion.rb b/lib/irb/completion.rb index 26d672847c..f75dd0ebcd 100644 --- a/lib/irb/completion.rb +++ b/lib/irb/completion.rb @@ -8,7 +8,7 @@ # require "readline" -require "rdoc" +autoload :RDoc, "rdoc" module IRB module InputCompletor # :nodoc: @@ -267,8 +267,8 @@ module IRB end end - RDocRIDriver = RDoc::RI::Driver.new PerfectMatchedProc = ->(matched) { + RDocRIDriver ||= RDoc::RI::Driver.new if matched =~ /\A(?:::)?RubyVM/ and not ENV['RUBY_YES_I_AM_NOT_A_NORMAL_USER'] File.open(File.join(__dir__, 'ruby_logo.aa')) do |f| RDocRIDriver.page do |io| |