Skip to Content Skip to Search
Methods
#
A
C
E
L
R

Constants

NO_OVERRIDE = 0
 
OVERRIDE_ALL = 0x02
 
OVERRIDE_PRIVATE_ONLY = 0x01
 

Attributes

[R] commands

Class Public methods

_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.

# File ruby/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()

# File ruby/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()

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

command_override_policies()

# File ruby/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:)

# File ruby/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)

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

# File ruby/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.

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