module IRB::ExtendCommand - Documentation for Ruby 3.3

# module IRB::ExtendCommand

### Constants

NO_OVERRIDE
OVERRIDE_ALL
OVERRIDE_PRIVATE_ONLY

### Attributes

commands[R]

### Public Class Methods

_register_with_aliases(name, command_class, *aliases) click to toggle source

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

    # 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() click to toggle source

    # 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() click to toggle source

    # File lib/irb/default_commands.rb, line 84
    def command_names
      command_override_policies.keys.map(&:to_s)
    end

command_override_policies() click to toggle source

    # 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:) click to toggle source

    # 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

load_command(command) click to toggle source

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

    # 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) click to toggle source

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

    # File lib/irb/command.rb, line 18
    def register(name, command_class)
      @commands[name.to_sym] = [command_class, []]
    end