summaryrefslogtreecommitdiff
path: root/lib/irb/extend-command.rb
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2022-11-07 09:29:24 -0800
committergit <svn-admin@ruby-lang.org>2022-11-07 17:29:28 +0000
commit9001e53e68d282493f513ed67824e4014fd01d57 (patch)
tree1b8070f10aa422b2d6510c56f93e924c0bb4abbf /lib/irb/extend-command.rb
parent7442cb461b32de2eec3b37f52d80752d30627de0 (diff)
[ruby/irb] Support non-string input in show_source
(https://github.com/ruby/irb/pull/430) * Support non-string input in show_source * Test show_source as a method
Diffstat (limited to 'lib/irb/extend-command.rb')
-rw-r--r--lib/irb/extend-command.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/irb/extend-command.rb b/lib/irb/extend-command.rb
index 08a258fc53..acc23c9920 100644
--- a/lib/irb/extend-command.rb
+++ b/lib/irb/extend-command.rb
@@ -147,6 +147,20 @@ module IRB # :nodoc:
]
+ # Convert a command name to its implementation class if such command exists
+ def self.load_command(command)
+ command = command.to_sym
+ @EXTEND_COMMANDS.each do |cmd_name, cmd_class, load_file, *aliases|
+ next if cmd_name != command && aliases.all? { |alias_name, _| alias_name != command }
+
+ if !defined?(ExtendCommand) || !ExtendCommand.const_defined?(cmd_class, false)
+ require_relative load_file
+ end
+ return ExtendCommand.const_get(cmd_class, false)
+ end
+ nil
+ end
+
# Installs the default irb commands:
#
# +irb_current_working_workspace+:: Context#main