123456789_123456789_123456789_123456789_123456789_

Module: IRB::Command

Constant Summary

Class Attribute Summary

Class Method Summary

Class Attribute Details

.commands (readonly)

[ GitHub ]

  
# File 'lib/irb/command.rb', line 14

attr_reader :commands

Class Method Details

._register_with_aliases(name, command_class, *aliases)

This API is for IRB’s internal use only and may change at any time. Please do NOT use it.

[ GitHub ]

  
# File 'lib/irb/default_commands.rb', line 41

def _register_with_aliases(name, command_class, *aliases)
  @commands[name.to_sym] = [command_class, aliases]
end

.all_commands_info

[ GitHub ]

  
# File 'lib/irb/default_commands.rb', line 45

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

[ GitHub ]

  
# File 'lib/irb/default_commands.rb', line 84

def command_names
  command_override_policies.keys.map(&:to_s)
end

.command_override_policies

[ GitHub ]

  
# File 'lib/irb/default_commands.rb', line 67

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:) ⇒ Boolean

[ GitHub ]

  
# File 'lib/irb/default_commands.rb', line 73

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

.extract_ruby_args(*args, **kwargs)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/irb/command/base.rb', line 13

def self.extract_ruby_args(*args, **kwargs)
  throw :EXTRACT_RUBY_ARGS, [args, kwargs]
end

.load_command(command)

Convert a command name to its implementation class if such command exists

[ GitHub ]

  
# File 'lib/irb/default_commands.rb', line 89

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)

Registers a command with the given name. Aliasing is intentionally not supported at the moment.

[ GitHub ]

  
# File 'lib/irb/command.rb', line 18

def register(name, command_class)
  @commands[name.to_sym] = [command_class, []]
end