Module: IRB::Command
- Defined in:
- lib/irb/command/ls.rb,
lib/irb/command.rb,
lib/irb/command/cd.rb,
lib/irb/command/base.rb,
lib/irb/command/chws.rb,
lib/irb/command/edit.rb,
lib/irb/command/exit.rb,
lib/irb/command/help.rb,
lib/irb/command/info.rb,
lib/irb/command/load.rb,
lib/irb/command/next.rb,
lib/irb/command/step.rb,
lib/irb/command/break.rb,
lib/irb/command/catch.rb,
lib/irb/command/debug.rb,
lib/irb/command/delete.rb,
lib/irb/command/finish.rb,
lib/irb/command/pushws.rb,
lib/irb/command/subirb.rb,
lib/irb/command/context.rb,
lib/irb/command/history.rb,
lib/irb/command/measure.rb,
lib/irb/command/continue.rb,
lib/irb/command/irb_info.rb,
lib/irb/command/show_doc.rb,
lib/irb/command/whereami.rb,
lib/irb/default_commands.rb,
lib/irb/command/backtrace.rb,
lib/irb/command/force_exit.rb,
lib/irb/command/disable_irb.rb,
lib/irb/command/show_source.rb,
lib/irb/command/internal_helpers.rb
Overview
:stopdoc:
Defined Under Namespace
Modules: RubyArgsExtractor Classes: Backtrace, Base, Break, CD, Catch, ChangeWorkspace, CommandArgumentError, Context, Continue, CurrentWorkingWorkspace, Debug, DebugCommand, Delete, DisableIrb, Edit, Exit, Finish, ForceExit, Foreground, Help, History, Info, IrbCommand, IrbInfo, Jobs, Kill, Load, LoaderCommand, Ls, Measure, MultiIRBCommand, Next, PopWorkspace, PushWorkspace, Require, ShowDoc, ShowSource, Source, Step, Whereami, Workspaces
Constant Summary collapse
- Nop =
Base
- NO_OVERRIDE =
0
- OVERRIDE_PRIVATE_ONLY =
0x01
- OVERRIDE_ALL =
0x02
Class Attribute Summary collapse
-
.commands ⇒ Object
readonly
Returns the value of attribute commands.
Class Method Summary collapse
-
._register_with_aliases(name, command_class, *aliases) ⇒ Object
This API is for IRB’s internal use only and may change at any time.
- .all_commands_info ⇒ Object
- .command_names ⇒ Object
- .command_override_policies ⇒ Object
- .execute_as_command?(name, public_method:, private_method:) ⇒ Boolean
- .extract_ruby_args(*args, **kwargs) ⇒ Object
-
.load_command(command) ⇒ Object
Convert a command name to its implementation class if such command exists.
-
.register(name, command_class) ⇒ Object
Registers a command with the given name.
Class Attribute Details
.commands ⇒ Object (readonly)
Returns the value of attribute commands.
14 15 16 |
# File 'lib/irb/command.rb', line 14 def commands @commands end |
Class Method Details
._register_with_aliases(name, command_class, *aliases) ⇒ Object
This API is for IRB’s internal use only and may change at any time. Please do NOT use it.
43 44 45 |
# File 'lib/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 ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/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 ⇒ Object
86 87 88 |
# File 'lib/irb/default_commands.rb', line 86 def command_names command_override_policies.keys.map(&:to_s) end |
.command_override_policies ⇒ Object
69 70 71 72 73 |
# File 'lib/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:) ⇒ Boolean
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/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 |
.extract_ruby_args(*args, **kwargs) ⇒ Object
14 15 16 |
# File 'lib/irb/command/base.rb', line 14 def extract_ruby_args(*args, **kwargs) throw :EXTRACT_RUBY_ARGS, [args, kwargs] end |
.load_command(command) ⇒ Object
Convert a command name to its implementation class if such command exists
91 92 93 94 95 96 97 98 99 |
# File 'lib/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) ⇒ Object
Registers a command with the given name. Aliasing is intentionally not supported at the moment.
18 19 20 |
# File 'lib/irb/command.rb', line 18 def register(name, command_class) @commands[name.to_sym] = [command_class, []] end |