123456789_123456789_123456789_123456789_123456789_

Module: IRB::ExtendCommandBundle

Relationships & Source Files
Defined in: lib/irb/default_commands.rb,
lib/irb/ext/use-loader.rb

Overview

Installs the default irb extensions command bundle.

Constant Summary

Class Method Summary

Instance Method Summary

Class Method Details

.all_commands_info

[ GitHub ]

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

def self.all_commands_info
  user_aliases = IRB.CurrentContext.command_aliases.each_with_object({}) do |(alias_name, target), result|
    result[target] ||= []
    result[target] << alias_name
  end

  Command.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 225

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

.command_override_policies

[ GitHub ]

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

def self.command_override_policies
  @@command_override_policies ||= Command.commands.flat_map do |cmd_name, (cmd_class, aliases)|
    [[cmd_name, OVERRIDE_ALL]] + aliases
  end.to_h
end

.def_extend_command(cmd_name, cmd_class, _, *aliases)

Drepcated. Use Command.regiser instead.

[ GitHub ]

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

def self.def_extend_command(cmd_name, cmd_class, _, *aliases)
  Command._register_with_aliases(cmd_name, cmd_class, *aliases)
  @@command_override_policies = nil
end

.execute_as_command?(name, public_method:, private_method:) ⇒ Boolean

[ GitHub ]

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

def self.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

[ GitHub ]

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

def self.load_command(command)
  command = command.to_sym
  Command.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

Instance Method Details

#irb_load(*opts, &b)

Loads the given file similarly to Kernel.load, see IrbLoader#irb_load

[ GitHub ]

  
# File 'lib/irb/ext/use-loader.rb', line 19

def irb_load(*opts, &b)
  Command::Load.execute(irb_context, *opts, &b)
end

#irb_require(*opts, &b)

Loads the given file similarly to Kernel.require

[ GitHub ]

  
# File 'lib/irb/ext/use-loader.rb', line 24

def irb_require(*opts, &b)
  Command::Require.execute(irb_context, *opts, &b)
end