Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby27/share/ruby/irb
File: extend-command.rb
# frozen_string_literal: false
[0] Fix | Delete
#
[1] Fix | Delete
# irb/extend-command.rb - irb extend command
[2] Fix | Delete
# $Release Version: 0.9.6$
[3] Fix | Delete
# $Revision$
[4] Fix | Delete
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
[5] Fix | Delete
#
[6] Fix | Delete
# --
[7] Fix | Delete
#
[8] Fix | Delete
#
[9] Fix | Delete
#
[10] Fix | Delete
module IRB # :nodoc:
[11] Fix | Delete
# Installs the default irb extensions command bundle.
[12] Fix | Delete
module ExtendCommandBundle
[13] Fix | Delete
EXCB = ExtendCommandBundle # :nodoc:
[14] Fix | Delete
[15] Fix | Delete
# See #install_alias_method.
[16] Fix | Delete
NO_OVERRIDE = 0
[17] Fix | Delete
# See #install_alias_method.
[18] Fix | Delete
OVERRIDE_PRIVATE_ONLY = 0x01
[19] Fix | Delete
# See #install_alias_method.
[20] Fix | Delete
OVERRIDE_ALL = 0x02
[21] Fix | Delete
[22] Fix | Delete
# Quits the current irb context
[23] Fix | Delete
#
[24] Fix | Delete
# +ret+ is the optional signal or message to send to Context#exit
[25] Fix | Delete
#
[26] Fix | Delete
# Same as <code>IRB.CurrentContext.exit</code>.
[27] Fix | Delete
def irb_exit(ret = 0)
[28] Fix | Delete
irb_context.exit(ret)
[29] Fix | Delete
end
[30] Fix | Delete
[31] Fix | Delete
# Displays current configuration.
[32] Fix | Delete
#
[33] Fix | Delete
# Modifying the configuration is achieved by sending a message to IRB.conf.
[34] Fix | Delete
def irb_context
[35] Fix | Delete
IRB.CurrentContext
[36] Fix | Delete
end
[37] Fix | Delete
[38] Fix | Delete
@ALIASES = [
[39] Fix | Delete
[:context, :irb_context, NO_OVERRIDE],
[40] Fix | Delete
[:conf, :irb_context, NO_OVERRIDE],
[41] Fix | Delete
[:irb_quit, :irb_exit, OVERRIDE_PRIVATE_ONLY],
[42] Fix | Delete
[:exit, :irb_exit, OVERRIDE_PRIVATE_ONLY],
[43] Fix | Delete
[:quit, :irb_exit, OVERRIDE_PRIVATE_ONLY],
[44] Fix | Delete
]
[45] Fix | Delete
[46] Fix | Delete
@EXTEND_COMMANDS = [
[47] Fix | Delete
[
[48] Fix | Delete
:irb_current_working_workspace, :CurrentWorkingWorkspace, "irb/cmd/chws",
[49] Fix | Delete
[:irb_print_working_workspace, OVERRIDE_ALL],
[50] Fix | Delete
[:irb_cwws, OVERRIDE_ALL],
[51] Fix | Delete
[:irb_pwws, OVERRIDE_ALL],
[52] Fix | Delete
[:cwws, NO_OVERRIDE],
[53] Fix | Delete
[:pwws, NO_OVERRIDE],
[54] Fix | Delete
[:irb_current_working_binding, OVERRIDE_ALL],
[55] Fix | Delete
[:irb_print_working_binding, OVERRIDE_ALL],
[56] Fix | Delete
[:irb_cwb, OVERRIDE_ALL],
[57] Fix | Delete
[:irb_pwb, OVERRIDE_ALL],
[58] Fix | Delete
],
[59] Fix | Delete
[
[60] Fix | Delete
:irb_change_workspace, :ChangeWorkspace, "irb/cmd/chws",
[61] Fix | Delete
[:irb_chws, OVERRIDE_ALL],
[62] Fix | Delete
[:irb_cws, OVERRIDE_ALL],
[63] Fix | Delete
[:chws, NO_OVERRIDE],
[64] Fix | Delete
[:cws, NO_OVERRIDE],
[65] Fix | Delete
[:irb_change_binding, OVERRIDE_ALL],
[66] Fix | Delete
[:irb_cb, OVERRIDE_ALL],
[67] Fix | Delete
[:cb, NO_OVERRIDE],
[68] Fix | Delete
],
[69] Fix | Delete
[70] Fix | Delete
[
[71] Fix | Delete
:irb_workspaces, :Workspaces, "irb/cmd/pushws",
[72] Fix | Delete
[:workspaces, NO_OVERRIDE],
[73] Fix | Delete
[:irb_bindings, OVERRIDE_ALL],
[74] Fix | Delete
[:bindings, NO_OVERRIDE],
[75] Fix | Delete
],
[76] Fix | Delete
[
[77] Fix | Delete
:irb_push_workspace, :PushWorkspace, "irb/cmd/pushws",
[78] Fix | Delete
[:irb_pushws, OVERRIDE_ALL],
[79] Fix | Delete
[:pushws, NO_OVERRIDE],
[80] Fix | Delete
[:irb_push_binding, OVERRIDE_ALL],
[81] Fix | Delete
[:irb_pushb, OVERRIDE_ALL],
[82] Fix | Delete
[:pushb, NO_OVERRIDE],
[83] Fix | Delete
],
[84] Fix | Delete
[
[85] Fix | Delete
:irb_pop_workspace, :PopWorkspace, "irb/cmd/pushws",
[86] Fix | Delete
[:irb_popws, OVERRIDE_ALL],
[87] Fix | Delete
[:popws, NO_OVERRIDE],
[88] Fix | Delete
[:irb_pop_binding, OVERRIDE_ALL],
[89] Fix | Delete
[:irb_popb, OVERRIDE_ALL],
[90] Fix | Delete
[:popb, NO_OVERRIDE],
[91] Fix | Delete
],
[92] Fix | Delete
[93] Fix | Delete
[
[94] Fix | Delete
:irb_load, :Load, "irb/cmd/load"],
[95] Fix | Delete
[
[96] Fix | Delete
:irb_require, :Require, "irb/cmd/load"],
[97] Fix | Delete
[
[98] Fix | Delete
:irb_source, :Source, "irb/cmd/load",
[99] Fix | Delete
[:source, NO_OVERRIDE],
[100] Fix | Delete
],
[101] Fix | Delete
[102] Fix | Delete
[
[103] Fix | Delete
:irb, :IrbCommand, "irb/cmd/subirb"],
[104] Fix | Delete
[
[105] Fix | Delete
:irb_jobs, :Jobs, "irb/cmd/subirb",
[106] Fix | Delete
[:jobs, NO_OVERRIDE],
[107] Fix | Delete
],
[108] Fix | Delete
[
[109] Fix | Delete
:irb_fg, :Foreground, "irb/cmd/subirb",
[110] Fix | Delete
[:fg, NO_OVERRIDE],
[111] Fix | Delete
],
[112] Fix | Delete
[
[113] Fix | Delete
:irb_kill, :Kill, "irb/cmd/subirb",
[114] Fix | Delete
[:kill, OVERRIDE_PRIVATE_ONLY],
[115] Fix | Delete
],
[116] Fix | Delete
[117] Fix | Delete
[
[118] Fix | Delete
:irb_help, :Help, "irb/cmd/help",
[119] Fix | Delete
[:help, NO_OVERRIDE],
[120] Fix | Delete
],
[121] Fix | Delete
[122] Fix | Delete
[
[123] Fix | Delete
:irb_info, :Info, "irb/cmd/info"
[124] Fix | Delete
],
[125] Fix | Delete
[126] Fix | Delete
]
[127] Fix | Delete
[128] Fix | Delete
# Installs the default irb commands:
[129] Fix | Delete
#
[130] Fix | Delete
# +irb_current_working_workspace+:: Context#main
[131] Fix | Delete
# +irb_change_workspace+:: Context#change_workspace
[132] Fix | Delete
# +irb_workspaces+:: Context#workspaces
[133] Fix | Delete
# +irb_push_workspace+:: Context#push_workspace
[134] Fix | Delete
# +irb_pop_workspace+:: Context#pop_workspace
[135] Fix | Delete
# +irb_load+:: #irb_load
[136] Fix | Delete
# +irb_require+:: #irb_require
[137] Fix | Delete
# +irb_source+:: IrbLoader#source_file
[138] Fix | Delete
# +irb+:: IRB.irb
[139] Fix | Delete
# +irb_jobs+:: JobManager
[140] Fix | Delete
# +irb_fg+:: JobManager#switch
[141] Fix | Delete
# +irb_kill+:: JobManager#kill
[142] Fix | Delete
# +irb_help+:: IRB@Command+line+options
[143] Fix | Delete
def self.install_extend_commands
[144] Fix | Delete
for args in @EXTEND_COMMANDS
[145] Fix | Delete
def_extend_command(*args)
[146] Fix | Delete
end
[147] Fix | Delete
end
[148] Fix | Delete
[149] Fix | Delete
# Evaluate the given +cmd_name+ on the given +cmd_class+ Class.
[150] Fix | Delete
#
[151] Fix | Delete
# Will also define any given +aliases+ for the method.
[152] Fix | Delete
#
[153] Fix | Delete
# The optional +load_file+ parameter will be required within the method
[154] Fix | Delete
# definition.
[155] Fix | Delete
def self.def_extend_command(cmd_name, cmd_class, load_file = nil, *aliases)
[156] Fix | Delete
case cmd_class
[157] Fix | Delete
when Symbol
[158] Fix | Delete
cmd_class = cmd_class.id2name
[159] Fix | Delete
when String
[160] Fix | Delete
when Class
[161] Fix | Delete
cmd_class = cmd_class.name
[162] Fix | Delete
end
[163] Fix | Delete
[164] Fix | Delete
if load_file
[165] Fix | Delete
line = __LINE__; eval %[
[166] Fix | Delete
def #{cmd_name}(*opts, &b)
[167] Fix | Delete
require "#{load_file}"
[168] Fix | Delete
arity = ExtendCommand::#{cmd_class}.instance_method(:execute).arity
[169] Fix | Delete
args = (1..(arity < 0 ? ~arity : arity)).map {|i| "arg" + i.to_s }
[170] Fix | Delete
args << "*opts" if arity < 0
[171] Fix | Delete
args << "&block"
[172] Fix | Delete
args = args.join(", ")
[173] Fix | Delete
line = __LINE__; eval %[
[174] Fix | Delete
unless self.class.class_variable_defined?(:@@#{cmd_name}_)
[175] Fix | Delete
self.class.class_variable_set(:@@#{cmd_name}_, true)
[176] Fix | Delete
def #{cmd_name}_(\#{args})
[177] Fix | Delete
ExtendCommand::#{cmd_class}.execute(irb_context, \#{args})
[178] Fix | Delete
end
[179] Fix | Delete
end
[180] Fix | Delete
], nil, __FILE__, line
[181] Fix | Delete
send :#{cmd_name}_, *opts, &b
[182] Fix | Delete
end
[183] Fix | Delete
], nil, __FILE__, line
[184] Fix | Delete
else
[185] Fix | Delete
line = __LINE__; eval %[
[186] Fix | Delete
def #{cmd_name}(*opts, &b)
[187] Fix | Delete
ExtendCommand::#{cmd_class}.execute(irb_context, *opts, &b)
[188] Fix | Delete
end
[189] Fix | Delete
], nil, __FILE__, line
[190] Fix | Delete
end
[191] Fix | Delete
[192] Fix | Delete
for ali, flag in aliases
[193] Fix | Delete
@ALIASES.push [ali, cmd_name, flag]
[194] Fix | Delete
end
[195] Fix | Delete
end
[196] Fix | Delete
[197] Fix | Delete
# Installs alias methods for the default irb commands, see
[198] Fix | Delete
# ::install_extend_commands.
[199] Fix | Delete
def install_alias_method(to, from, override = NO_OVERRIDE)
[200] Fix | Delete
to = to.id2name unless to.kind_of?(String)
[201] Fix | Delete
from = from.id2name unless from.kind_of?(String)
[202] Fix | Delete
[203] Fix | Delete
if override == OVERRIDE_ALL or
[204] Fix | Delete
(override == OVERRIDE_PRIVATE_ONLY) && !respond_to?(to) or
[205] Fix | Delete
(override == NO_OVERRIDE) && !respond_to?(to, true)
[206] Fix | Delete
target = self
[207] Fix | Delete
(class << self; self; end).instance_eval{
[208] Fix | Delete
if target.respond_to?(to, true) &&
[209] Fix | Delete
!target.respond_to?(EXCB.irb_original_method_name(to), true)
[210] Fix | Delete
alias_method(EXCB.irb_original_method_name(to), to)
[211] Fix | Delete
end
[212] Fix | Delete
alias_method to, from
[213] Fix | Delete
}
[214] Fix | Delete
else
[215] Fix | Delete
print "irb: warn: can't alias #{to} from #{from}.\n"
[216] Fix | Delete
end
[217] Fix | Delete
end
[218] Fix | Delete
[219] Fix | Delete
def self.irb_original_method_name(method_name) # :nodoc:
[220] Fix | Delete
"irb_" + method_name + "_org"
[221] Fix | Delete
end
[222] Fix | Delete
[223] Fix | Delete
# Installs alias methods for the default irb commands on the given object
[224] Fix | Delete
# using #install_alias_method.
[225] Fix | Delete
def self.extend_object(obj)
[226] Fix | Delete
unless (class << obj; ancestors; end).include?(EXCB)
[227] Fix | Delete
super
[228] Fix | Delete
for ali, com, flg in @ALIASES
[229] Fix | Delete
obj.install_alias_method(ali, com, flg)
[230] Fix | Delete
end
[231] Fix | Delete
end
[232] Fix | Delete
end
[233] Fix | Delete
[234] Fix | Delete
install_extend_commands
[235] Fix | Delete
end
[236] Fix | Delete
[237] Fix | Delete
# Extends methods for the Context module
[238] Fix | Delete
module ContextExtender
[239] Fix | Delete
CE = ContextExtender # :nodoc:
[240] Fix | Delete
[241] Fix | Delete
@EXTEND_COMMANDS = [
[242] Fix | Delete
[:eval_history=, "irb/ext/history.rb"],
[243] Fix | Delete
[:use_tracer=, "irb/ext/tracer.rb"],
[244] Fix | Delete
[:use_loader=, "irb/ext/use-loader.rb"],
[245] Fix | Delete
[:save_history=, "irb/ext/save-history.rb"],
[246] Fix | Delete
]
[247] Fix | Delete
[248] Fix | Delete
# Installs the default context extensions as irb commands:
[249] Fix | Delete
#
[250] Fix | Delete
# Context#eval_history=:: +irb/ext/history.rb+
[251] Fix | Delete
# Context#use_tracer=:: +irb/ext/tracer.rb+
[252] Fix | Delete
# Context#use_loader=:: +irb/ext/use-loader.rb+
[253] Fix | Delete
# Context#save_history=:: +irb/ext/save-history.rb+
[254] Fix | Delete
def self.install_extend_commands
[255] Fix | Delete
for args in @EXTEND_COMMANDS
[256] Fix | Delete
def_extend_command(*args)
[257] Fix | Delete
end
[258] Fix | Delete
end
[259] Fix | Delete
[260] Fix | Delete
# Evaluate the given +command+ from the given +load_file+ on the Context
[261] Fix | Delete
# module.
[262] Fix | Delete
#
[263] Fix | Delete
# Will also define any given +aliases+ for the method.
[264] Fix | Delete
def self.def_extend_command(cmd_name, load_file, *aliases)
[265] Fix | Delete
line = __LINE__; Context.module_eval %[
[266] Fix | Delete
def #{cmd_name}(*opts, &b)
[267] Fix | Delete
Context.module_eval {remove_method(:#{cmd_name})}
[268] Fix | Delete
require "#{load_file}"
[269] Fix | Delete
send :#{cmd_name}, *opts, &b
[270] Fix | Delete
end
[271] Fix | Delete
for ali in aliases
[272] Fix | Delete
alias_method ali, cmd_name
[273] Fix | Delete
end
[274] Fix | Delete
], __FILE__, line
[275] Fix | Delete
end
[276] Fix | Delete
[277] Fix | Delete
CE.install_extend_commands
[278] Fix | Delete
end
[279] Fix | Delete
[280] Fix | Delete
# A convenience module for extending Ruby methods.
[281] Fix | Delete
module MethodExtender
[282] Fix | Delete
# Extends the given +base_method+ with a prefix call to the given
[283] Fix | Delete
# +extend_method+.
[284] Fix | Delete
def def_pre_proc(base_method, extend_method)
[285] Fix | Delete
base_method = base_method.to_s
[286] Fix | Delete
extend_method = extend_method.to_s
[287] Fix | Delete
[288] Fix | Delete
alias_name = new_alias_name(base_method)
[289] Fix | Delete
module_eval %[
[290] Fix | Delete
alias_method alias_name, base_method
[291] Fix | Delete
def #{base_method}(*opts)
[292] Fix | Delete
send :#{extend_method}, *opts
[293] Fix | Delete
send :#{alias_name}, *opts
[294] Fix | Delete
end
[295] Fix | Delete
]
[296] Fix | Delete
end
[297] Fix | Delete
[298] Fix | Delete
# Extends the given +base_method+ with a postfix call to the given
[299] Fix | Delete
# +extend_method+.
[300] Fix | Delete
def def_post_proc(base_method, extend_method)
[301] Fix | Delete
base_method = base_method.to_s
[302] Fix | Delete
extend_method = extend_method.to_s
[303] Fix | Delete
[304] Fix | Delete
alias_name = new_alias_name(base_method)
[305] Fix | Delete
module_eval %[
[306] Fix | Delete
alias_method alias_name, base_method
[307] Fix | Delete
def #{base_method}(*opts)
[308] Fix | Delete
send :#{alias_name}, *opts
[309] Fix | Delete
send :#{extend_method}, *opts
[310] Fix | Delete
end
[311] Fix | Delete
]
[312] Fix | Delete
end
[313] Fix | Delete
[314] Fix | Delete
# Returns a unique method name to use as an alias for the given +name+.
[315] Fix | Delete
#
[316] Fix | Delete
# Usually returns <code>#{prefix}#{name}#{postfix}<num></code>, example:
[317] Fix | Delete
#
[318] Fix | Delete
# new_alias_name('foo') #=> __alias_of__foo__
[319] Fix | Delete
# def bar; end
[320] Fix | Delete
# new_alias_name('bar') #=> __alias_of__bar__2
[321] Fix | Delete
def new_alias_name(name, prefix = "__alias_of__", postfix = "__")
[322] Fix | Delete
base_name = "#{prefix}#{name}#{postfix}"
[323] Fix | Delete
all_methods = instance_methods(true) + private_instance_methods(true)
[324] Fix | Delete
same_methods = all_methods.grep(/^#{Regexp.quote(base_name)}[0-9]*$/)
[325] Fix | Delete
return base_name if same_methods.empty?
[326] Fix | Delete
no = same_methods.size
[327] Fix | Delete
while !same_methods.include?(alias_name = base_name + no)
[328] Fix | Delete
no += 1
[329] Fix | Delete
end
[330] Fix | Delete
alias_name
[331] Fix | Delete
end
[332] Fix | Delete
end
[333] Fix | Delete
end
[334] Fix | Delete
[335] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function