Module: IRB::ExtendCommandBundle
Relationships & Source Files | |
Defined in: | lib/irb/extend-command.rb, lib/irb/ext/use-loader.rb |
Overview
Installs the default irb extensions command bundle.
Constant Summary
-
EXCB =
Internal use only
# File 'lib/irb/extend-command.rb', line 15ExtendCommandBundle
-
NO_OVERRIDE =
# File 'lib/irb/extend-command.rb', line 18
0
-
OVERRIDE_ALL =
# File 'lib/irb/extend-command.rb', line 22
0x02
-
OVERRIDE_PRIVATE_ONLY =
# File 'lib/irb/extend-command.rb', line 20
0x01
Class Method Summary
-
.def_extend_command(cmd_name, cmd_class, load_file = nil, *aliases)
Evaluate the given
cmd_name
on the givencmd_class
Class. -
.extend_object(obj)
Installs alias methods for the default irb commands on the given object using #install_alias_method.
-
.install_extend_commands
Installs the default irb commands:
- .irb_original_method_name(method_name) Internal use only
Instance Method Summary
-
#install_alias_method(to, from, override = NO_OVERRIDE)
Installs alias methods for the default irb commands, see .install_extend_commands.
-
#irb_context
Displays current configuration.
-
#irb_exit(ret = 0)
Quits the current irb context.
-
#irb_load(*opts, &b)
Loads the given file similarly to
Kernel.load
, see IrbLoader#irb_load -
#irb_require(*opts, &b)
Loads the given file similarly to
Kernel.require
Class Method Details
.def_extend_command(cmd_name, cmd_class, load_file = nil, *aliases)
Evaluate the given cmd_name
on the given cmd_class
Class.
Will also define any given aliases
for the method.
The optional load_file
parameter will be required within the method definition.
# File 'lib/irb/extend-command.rb', line 131
def self.def_extend_command(cmd_name, cmd_class, load_file = nil, *aliases) case cmd_class when Symbol cmd_class = cmd_class.id2name when String when Class cmd_class = cmd_class.name end if load_file line = __LINE__; eval %[ def #{cmd_name}(*opts, &b) require "#{load_file}" arity = ExtendCommand::#{cmd_class}.instance_method(:execute).arity args = (1..(arity < 0 ? ~arity : arity)).map {|i| "arg" + i.to_s } args << "*opts" if arity < 0 args << "&block" args = args.join(", ") line = __LINE__; eval %[ def #{cmd_name}(\#{args}) ExtendCommand::#{cmd_class}.execute(irb_context, \#{args}) end ], nil, __FILE__, line send :#{cmd_name}, *opts, &b end ], nil, __FILE__, line else line = __LINE__; eval %[ def #{cmd_name}(*opts, &b) ExtendCommand::#{cmd_class}.execute(irb_context, *opts, &b) end ], nil, __FILE__, line end for ali, flag in aliases @ALIASES.push [ali, cmd_name, flag] end end
.extend_object(obj)
Installs alias methods for the default irb commands on the given object using #install_alias_method.
# File 'lib/irb/extend-command.rb', line 198
def self.extend_object(obj) unless (class << obj; ancestors; end).include?(EXCB) super for ali, com, flg in @ALIASES obj.install_alias_method(ali, com, flg) end end end
.install_extend_commands
Installs the default irb commands:
irb_current_working_workspace
irb_change_workspace
irb_workspaces
irb_push_workspace
irb_pop_workspace
- #irb_load
- #irb_require
irb_source
- IRB.irb
irb_jobs
irb_fg
irb_kill
irb_help
-
IRB@Command+line+options
# File 'lib/irb/extend-command.rb', line 119
def self.install_extend_commands for args in @EXTEND_COMMANDS def_extend_command(*args) end end
.irb_original_method_name(method_name)
# File 'lib/irb/extend-command.rb', line 192
def self.irb_original_method_name(method_name) # :nodoc: "irb_" + method_name + "_org" end
Instance Method Details
#install_alias_method(to, from, override = NO_OVERRIDE)
Installs alias methods for the default irb commands, see .install_extend_commands.
# File 'lib/irb/extend-command.rb', line 172
def install_alias_method(to, from, override = NO_OVERRIDE) to = to.id2name unless to.kind_of?(String) from = from.id2name unless from.kind_of?(String) if override == OVERRIDE_ALL or (override == OVERRIDE_PRIVATE_ONLY) && !respond_to?(to) or (override == NO_OVERRIDE) && !respond_to?(to, true) target = self (class << self; self; end).instance_eval{ if target.respond_to?(to, true) && !target.respond_to?(EXCB.irb_original_method_name(to), true) alias_method(EXCB.irb_original_method_name(to), to) end alias_method to, from } else print "irb: warn: can't alias #{to} from #{from}.\n" end end
#irb_context
Displays current configuration.
Modifing the configuration is achieved by sending a message to IRB.conf.
# File 'lib/irb/extend-command.rb', line 36
def irb_context IRB.CurrentContext end
#irb_exit(ret = 0)
Quits the current irb context
ret
is the optional signal or message to send to Context#exit
Same as IRB.CurrentContext.exit
.
# File 'lib/irb/extend-command.rb', line 29
def irb_exit(ret = 0) irb_context.exit(ret) end
#irb_load(*opts, &b)
Loads the given file similarly to Kernel.load
, see IrbLoader#irb_load
# File 'lib/irb/ext/use-loader.rb', line 24
def irb_load(*opts, &b) ExtendCommand::Load.execute(irb_context, *opts, &b) end
#irb_require(*opts, &b)
Loads the given file similarly to Kernel.require
# File 'lib/irb/ext/use-loader.rb', line 28
def irb_require(*opts, &b) ExtendCommand::Require.execute(irb_context, *opts, &b) end