模块 IRB::ExtendCommand
常量
- NO_OVERRIDE
- OVERRIDE_ALL
- OVERRIDE_PRIVATE_ONLY
属性
commands[R]
公共类方法
_register_with_aliases(name, command_class, *aliases) 点击切换源代码
此 API 仅供 IRB 内部使用,可能会随时更改。请不要使用它。
# File irb/default_commands.rb, line 43 def _register_with_aliases(name, command_class, *aliases) @commands[name.to_sym] = [command_class, aliases] end
all_commands_info() 点击切换源代码
# File irb/default_commands.rb, line 47 def all_commands_info user_aliases = IRB.CurrentContext.command_aliases.each_with_object({}) do |(alias_name, target), result| result[target] ||= [] result[target] << alias_name end commands.map do |command_name, (command_class, aliases)| aliases = aliases.map { |a| a.first } if additional_aliases = user_aliases[command_name] aliases += additional_aliases end display_name = aliases.shift || command_name { display_name: display_name, description: command_class.description, category: command_class.category } end end
command_names() 点击切换源代码
# File irb/default_commands.rb, line 86 def command_names command_override_policies.keys.map(&:to_s) end
command_override_policies() 点击切换源代码
# File irb/default_commands.rb, line 69 def command_override_policies @@command_override_policies ||= commands.flat_map do |cmd_name, (cmd_class, aliases)| [[cmd_name, OVERRIDE_ALL]] + aliases end.to_h end
execute_as_command?(name, public_method:, private_method:) 点击切换源代码
# File irb/default_commands.rb, line 75 def execute_as_command?(name, public_method:, private_method:) case command_override_policies[name] when OVERRIDE_ALL true when OVERRIDE_PRIVATE_ONLY !public_method when NO_OVERRIDE !public_method && !private_method end end
load_command(command) 点击切换源代码
如果存在这样的命令,则将命令名称转换为其实现类
# File irb/default_commands.rb, line 91 def load_command(command) command = command.to_sym commands.each do |command_name, (command_class, aliases)| if command_name == command || aliases.any? { |alias_name, _| alias_name == command } return command_class end end nil end
register(name, command_class) 点击切换源代码
使用给定的名称注册命令。目前有意不支持别名。
# File irb/command.rb, line 18 def register(name, command_class) @commands[name.to_sym] = [command_class, []] end