summaryrefslogtreecommitdiff
path: root/lib/irb
diff options
context:
space:
mode:
authorStan Lo <stan001212@gmail.com>2023-04-24 15:10:32 +0100
committergit <svn-admin@ruby-lang.org>2023-04-24 14:10:36 +0000
commit73fc81199de5e567e38f7ea9067260eb6866cbf9 (patch)
tree3d98586fa270eb64e1a11164bf74227324b0bc44 /lib/irb
parent805899dda29e36a42ffd9e076b9296f3bf13af5a (diff)
[ruby/irb] Simplify the help command's implementation
(https://github.com/ruby/irb/pull/564) The current method-redefining approach brings little benefit, makes it harder to understand the code, and causes warnings like: > warning: method redefined; discarding old execute This patch simplifies it while displaying more helpful message when rdoc couldn't be loaded.
Diffstat (limited to 'lib/irb')
-rw-r--r--lib/irb/cmd/help.rb26
1 files changed, 12 insertions, 14 deletions
diff --git a/lib/irb/cmd/help.rb b/lib/irb/cmd/help.rb
index 9896fa9db1..539d20a119 100644
--- a/lib/irb/cmd/help.rb
+++ b/lib/irb/cmd/help.rb
@@ -26,17 +26,15 @@ module IRB
def execute(*names)
require 'rdoc/ri/driver'
- opts = RDoc::RI::Driver.process_args([])
- IRB::ExtendCommand::Help.const_set(:Ri, RDoc::RI::Driver.new(opts))
- rescue LoadError, SystemExit
- IRB::ExtendCommand::Help.remove_method(:execute)
- # raise NoMethodError in ensure
- else
- def execute(*names)
- if names.empty?
- Ri.interactive
- return
- end
+
+ unless self.class.const_defined?(:Ri)
+ opts = RDoc::RI::Driver.process_args([])
+ self.class.const_set(:Ri, RDoc::RI::Driver.new(opts))
+ end
+
+ if names.empty?
+ Ri.interactive
+ else
names.each do |name|
begin
Ri.display_name(name.to_s)
@@ -44,11 +42,11 @@ module IRB
puts $!.message
end
end
- nil
end
+
nil
- ensure
- execute(*names)
+ rescue LoadError, SystemExit
+ warn "Can't display document because `rdoc` is not installed."
end
end
end