Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby27/share/ruby/irb
File: completion.rb
# frozen_string_literal: false
[0] Fix | Delete
#
[1] Fix | Delete
# irb/completion.rb -
[2] Fix | Delete
# $Release Version: 0.9$
[3] Fix | Delete
# $Revision$
[4] Fix | Delete
# by Keiju ISHITSUKA(keiju@ishitsuka.com)
[5] Fix | Delete
# From Original Idea of shugo@ruby-lang.org
[6] Fix | Delete
#
[7] Fix | Delete
[8] Fix | Delete
autoload :RDoc, "rdoc"
[9] Fix | Delete
[10] Fix | Delete
module IRB
[11] Fix | Delete
module InputCompletor # :nodoc:
[12] Fix | Delete
[13] Fix | Delete
[14] Fix | Delete
# Set of reserved words used by Ruby, you should not use these for
[15] Fix | Delete
# constants or variables
[16] Fix | Delete
ReservedWords = %w[
[17] Fix | Delete
__ENCODING__ __LINE__ __FILE__
[18] Fix | Delete
BEGIN END
[19] Fix | Delete
alias and
[20] Fix | Delete
begin break
[21] Fix | Delete
case class
[22] Fix | Delete
def defined? do
[23] Fix | Delete
else elsif end ensure
[24] Fix | Delete
false for
[25] Fix | Delete
if in
[26] Fix | Delete
module
[27] Fix | Delete
next nil not
[28] Fix | Delete
or
[29] Fix | Delete
redo rescue retry return
[30] Fix | Delete
self super
[31] Fix | Delete
then true
[32] Fix | Delete
undef unless until
[33] Fix | Delete
when while
[34] Fix | Delete
yield
[35] Fix | Delete
]
[36] Fix | Delete
[37] Fix | Delete
BASIC_WORD_BREAK_CHARACTERS = " \t\n`><=;|&{("
[38] Fix | Delete
[39] Fix | Delete
CompletionProc = proc { |input|
[40] Fix | Delete
retrieve_completion_data(input).compact.map{ |i| i.encode(Encoding.default_external) }
[41] Fix | Delete
}
[42] Fix | Delete
[43] Fix | Delete
def self.retrieve_completion_data(input, bind: IRB.conf[:MAIN_CONTEXT].workspace.binding, doc_namespace: false)
[44] Fix | Delete
case input
[45] Fix | Delete
when /^((["'`]).*\2)\.([^.]*)$/
[46] Fix | Delete
# String
[47] Fix | Delete
receiver = $1
[48] Fix | Delete
message = Regexp.quote($3)
[49] Fix | Delete
[50] Fix | Delete
candidates = String.instance_methods.collect{|m| m.to_s}
[51] Fix | Delete
if doc_namespace
[52] Fix | Delete
"String.#{message}"
[53] Fix | Delete
else
[54] Fix | Delete
select_message(receiver, message, candidates)
[55] Fix | Delete
end
[56] Fix | Delete
[57] Fix | Delete
when /^(\/[^\/]*\/)\.([^.]*)$/
[58] Fix | Delete
# Regexp
[59] Fix | Delete
receiver = $1
[60] Fix | Delete
message = Regexp.quote($2)
[61] Fix | Delete
[62] Fix | Delete
candidates = Regexp.instance_methods.collect{|m| m.to_s}
[63] Fix | Delete
if doc_namespace
[64] Fix | Delete
"Regexp.#{message}"
[65] Fix | Delete
else
[66] Fix | Delete
select_message(receiver, message, candidates)
[67] Fix | Delete
end
[68] Fix | Delete
[69] Fix | Delete
when /^([^\]]*\])\.([^.]*)$/
[70] Fix | Delete
# Array
[71] Fix | Delete
receiver = $1
[72] Fix | Delete
message = Regexp.quote($2)
[73] Fix | Delete
[74] Fix | Delete
candidates = Array.instance_methods.collect{|m| m.to_s}
[75] Fix | Delete
if doc_namespace
[76] Fix | Delete
"Array.#{message}"
[77] Fix | Delete
else
[78] Fix | Delete
select_message(receiver, message, candidates)
[79] Fix | Delete
end
[80] Fix | Delete
[81] Fix | Delete
when /^([^\}]*\})\.([^.]*)$/
[82] Fix | Delete
# Proc or Hash
[83] Fix | Delete
receiver = $1
[84] Fix | Delete
message = Regexp.quote($2)
[85] Fix | Delete
[86] Fix | Delete
proc_candidates = Proc.instance_methods.collect{|m| m.to_s}
[87] Fix | Delete
hash_candidates = Hash.instance_methods.collect{|m| m.to_s}
[88] Fix | Delete
if doc_namespace
[89] Fix | Delete
["Proc.#{message}", "Hash.#{message}"]
[90] Fix | Delete
else
[91] Fix | Delete
select_message(receiver, message, proc_candidates | hash_candidates)
[92] Fix | Delete
end
[93] Fix | Delete
[94] Fix | Delete
when /^(:[^:.]*)$/
[95] Fix | Delete
# Symbol
[96] Fix | Delete
return nil if doc_namespace
[97] Fix | Delete
sym = $1
[98] Fix | Delete
candidates = Symbol.all_symbols.collect do |s|
[99] Fix | Delete
":" + s.id2name.encode(Encoding.default_external)
[100] Fix | Delete
rescue Encoding::UndefinedConversionError
[101] Fix | Delete
# ignore
[102] Fix | Delete
end
[103] Fix | Delete
candidates.grep(/^#{Regexp.quote(sym)}/)
[104] Fix | Delete
[105] Fix | Delete
when /^::([A-Z][^:\.\(]*)$/
[106] Fix | Delete
# Absolute Constant or class methods
[107] Fix | Delete
receiver = $1
[108] Fix | Delete
candidates = Object.constants.collect{|m| m.to_s}
[109] Fix | Delete
if doc_namespace
[110] Fix | Delete
candidates.find { |i| i == receiver }
[111] Fix | Delete
else
[112] Fix | Delete
candidates.grep(/^#{receiver}/).collect{|e| "::" + e}
[113] Fix | Delete
end
[114] Fix | Delete
[115] Fix | Delete
when /^([A-Z].*)::([^:.]*)$/
[116] Fix | Delete
# Constant or class methods
[117] Fix | Delete
receiver = $1
[118] Fix | Delete
message = Regexp.quote($2)
[119] Fix | Delete
begin
[120] Fix | Delete
candidates = eval("#{receiver}.constants.collect{|m| m.to_s}", bind)
[121] Fix | Delete
candidates |= eval("#{receiver}.methods.collect{|m| m.to_s}", bind)
[122] Fix | Delete
rescue Exception
[123] Fix | Delete
candidates = []
[124] Fix | Delete
end
[125] Fix | Delete
if doc_namespace
[126] Fix | Delete
"#{receiver}::#{message}"
[127] Fix | Delete
else
[128] Fix | Delete
select_message(receiver, message, candidates, "::")
[129] Fix | Delete
end
[130] Fix | Delete
[131] Fix | Delete
when /^(:[^:.]+)(\.|::)([^.]*)$/
[132] Fix | Delete
# Symbol
[133] Fix | Delete
receiver = $1
[134] Fix | Delete
sep = $2
[135] Fix | Delete
message = Regexp.quote($3)
[136] Fix | Delete
[137] Fix | Delete
candidates = Symbol.instance_methods.collect{|m| m.to_s}
[138] Fix | Delete
if doc_namespace
[139] Fix | Delete
"Symbol.#{message}"
[140] Fix | Delete
else
[141] Fix | Delete
select_message(receiver, message, candidates, sep)
[142] Fix | Delete
end
[143] Fix | Delete
[144] Fix | Delete
when /^(?<num>-?(?:0[dbo])?[0-9_]+(?:\.[0-9_]+)?(?:(?:[eE][+-]?[0-9]+)?i?|r)?)(?<sep>\.|::)(?<mes>[^.]*)$/
[145] Fix | Delete
# Numeric
[146] Fix | Delete
receiver = $~[:num]
[147] Fix | Delete
sep = $~[:sep]
[148] Fix | Delete
message = Regexp.quote($~[:mes])
[149] Fix | Delete
[150] Fix | Delete
begin
[151] Fix | Delete
instance = eval(receiver, bind)
[152] Fix | Delete
if doc_namespace
[153] Fix | Delete
"#{instance.class.name}.#{message}"
[154] Fix | Delete
else
[155] Fix | Delete
candidates = instance.methods.collect{|m| m.to_s}
[156] Fix | Delete
select_message(receiver, message, candidates, sep)
[157] Fix | Delete
end
[158] Fix | Delete
rescue Exception
[159] Fix | Delete
if doc_namespace
[160] Fix | Delete
nil
[161] Fix | Delete
else
[162] Fix | Delete
candidates = []
[163] Fix | Delete
end
[164] Fix | Delete
end
[165] Fix | Delete
[166] Fix | Delete
when /^(-?0x[0-9a-fA-F_]+)(\.|::)([^.]*)$/
[167] Fix | Delete
# Numeric(0xFFFF)
[168] Fix | Delete
receiver = $1
[169] Fix | Delete
sep = $2
[170] Fix | Delete
message = Regexp.quote($3)
[171] Fix | Delete
[172] Fix | Delete
begin
[173] Fix | Delete
instance = eval(receiver, bind)
[174] Fix | Delete
if doc_namespace
[175] Fix | Delete
"#{instance.class.name}.#{message}"
[176] Fix | Delete
else
[177] Fix | Delete
candidates = instance.methods.collect{|m| m.to_s}
[178] Fix | Delete
select_message(receiver, message, candidates, sep)
[179] Fix | Delete
end
[180] Fix | Delete
rescue Exception
[181] Fix | Delete
if doc_namespace
[182] Fix | Delete
nil
[183] Fix | Delete
else
[184] Fix | Delete
candidates = []
[185] Fix | Delete
end
[186] Fix | Delete
end
[187] Fix | Delete
[188] Fix | Delete
when /^(\$[^.]*)$/
[189] Fix | Delete
# global var
[190] Fix | Delete
gvar = $1
[191] Fix | Delete
all_gvars = global_variables.collect{|m| m.to_s}
[192] Fix | Delete
if doc_namespace
[193] Fix | Delete
all_gvars.find{ |i| i == gvar }
[194] Fix | Delete
else
[195] Fix | Delete
all_gvars.grep(Regexp.new(Regexp.quote(gvar)))
[196] Fix | Delete
end
[197] Fix | Delete
[198] Fix | Delete
when /^([^."].*)(\.|::)([^.]*)$/
[199] Fix | Delete
# variable.func or func.func
[200] Fix | Delete
receiver = $1
[201] Fix | Delete
sep = $2
[202] Fix | Delete
message = Regexp.quote($3)
[203] Fix | Delete
[204] Fix | Delete
gv = eval("global_variables", bind).collect{|m| m.to_s}.push("true", "false", "nil")
[205] Fix | Delete
lv = eval("local_variables", bind).collect{|m| m.to_s}
[206] Fix | Delete
iv = eval("instance_variables", bind).collect{|m| m.to_s}
[207] Fix | Delete
cv = eval("self.class.constants", bind).collect{|m| m.to_s}
[208] Fix | Delete
[209] Fix | Delete
if (gv | lv | iv | cv).include?(receiver) or /^[A-Z]/ =~ receiver && /\./ !~ receiver
[210] Fix | Delete
# foo.func and foo is var. OR
[211] Fix | Delete
# foo::func and foo is var. OR
[212] Fix | Delete
# foo::Const and foo is var. OR
[213] Fix | Delete
# Foo::Bar.func
[214] Fix | Delete
begin
[215] Fix | Delete
candidates = []
[216] Fix | Delete
rec = eval(receiver, bind)
[217] Fix | Delete
if sep == "::" and rec.kind_of?(Module)
[218] Fix | Delete
candidates = rec.constants.collect{|m| m.to_s}
[219] Fix | Delete
end
[220] Fix | Delete
candidates |= rec.methods.collect{|m| m.to_s}
[221] Fix | Delete
rescue Exception
[222] Fix | Delete
candidates = []
[223] Fix | Delete
end
[224] Fix | Delete
else
[225] Fix | Delete
# func1.func2
[226] Fix | Delete
candidates = []
[227] Fix | Delete
to_ignore = ignored_modules
[228] Fix | Delete
ObjectSpace.each_object(Module){|m|
[229] Fix | Delete
next if (to_ignore.include?(m) rescue true)
[230] Fix | Delete
candidates.concat m.instance_methods(false).collect{|x| x.to_s}
[231] Fix | Delete
}
[232] Fix | Delete
candidates.sort!
[233] Fix | Delete
candidates.uniq!
[234] Fix | Delete
end
[235] Fix | Delete
if doc_namespace
[236] Fix | Delete
"#{rec.class.name}#{sep}#{candidates.find{ |i| i == message }}"
[237] Fix | Delete
else
[238] Fix | Delete
select_message(receiver, message, candidates, sep)
[239] Fix | Delete
end
[240] Fix | Delete
[241] Fix | Delete
when /^\.([^.]*)$/
[242] Fix | Delete
# unknown(maybe String)
[243] Fix | Delete
[244] Fix | Delete
receiver = ""
[245] Fix | Delete
message = Regexp.quote($1)
[246] Fix | Delete
[247] Fix | Delete
candidates = String.instance_methods(true).collect{|m| m.to_s}
[248] Fix | Delete
if doc_namespace
[249] Fix | Delete
"String.#{candidates.find{ |i| i == message }}"
[250] Fix | Delete
else
[251] Fix | Delete
select_message(receiver, message, candidates)
[252] Fix | Delete
end
[253] Fix | Delete
[254] Fix | Delete
else
[255] Fix | Delete
candidates = eval("methods | private_methods | local_variables | instance_variables | self.class.constants", bind).collect{|m| m.to_s}
[256] Fix | Delete
candidates |= ReservedWords
[257] Fix | Delete
[258] Fix | Delete
if doc_namespace
[259] Fix | Delete
candidates.find{ |i| i == input }
[260] Fix | Delete
else
[261] Fix | Delete
candidates.grep(/^#{Regexp.quote(input)}/)
[262] Fix | Delete
end
[263] Fix | Delete
end
[264] Fix | Delete
end
[265] Fix | Delete
[266] Fix | Delete
PerfectMatchedProc = ->(matched, bind: IRB.conf[:MAIN_CONTEXT].workspace.binding) {
[267] Fix | Delete
RDocRIDriver ||= RDoc::RI::Driver.new
[268] Fix | Delete
if matched =~ /\A(?:::)?RubyVM/ and not ENV['RUBY_YES_I_AM_NOT_A_NORMAL_USER']
[269] Fix | Delete
IRB.send(:easter_egg)
[270] Fix | Delete
return
[271] Fix | Delete
end
[272] Fix | Delete
namespace = retrieve_completion_data(matched, bind: bind, doc_namespace: true)
[273] Fix | Delete
return unless namespace
[274] Fix | Delete
if namespace.is_a?(Array)
[275] Fix | Delete
out = RDoc::Markup::Document.new
[276] Fix | Delete
namespace.each do |m|
[277] Fix | Delete
begin
[278] Fix | Delete
RDocRIDriver.add_method(out, m)
[279] Fix | Delete
rescue RDoc::RI::Driver::NotFoundError
[280] Fix | Delete
end
[281] Fix | Delete
end
[282] Fix | Delete
RDocRIDriver.display(out)
[283] Fix | Delete
else
[284] Fix | Delete
begin
[285] Fix | Delete
RDocRIDriver.display_names([namespace])
[286] Fix | Delete
rescue RDoc::RI::Driver::NotFoundError
[287] Fix | Delete
end
[288] Fix | Delete
end
[289] Fix | Delete
}
[290] Fix | Delete
[291] Fix | Delete
# Set of available operators in Ruby
[292] Fix | Delete
Operators = %w[% & * ** + - / < << <= <=> == === =~ > >= >> [] []= ^ ! != !~]
[293] Fix | Delete
[294] Fix | Delete
def self.select_message(receiver, message, candidates, sep = ".")
[295] Fix | Delete
candidates.grep(/^#{message}/).collect do |e|
[296] Fix | Delete
case e
[297] Fix | Delete
when /^[a-zA-Z_]/
[298] Fix | Delete
receiver + sep + e
[299] Fix | Delete
when /^[0-9]/
[300] Fix | Delete
when *Operators
[301] Fix | Delete
#receiver + " " + e
[302] Fix | Delete
end
[303] Fix | Delete
end
[304] Fix | Delete
end
[305] Fix | Delete
[306] Fix | Delete
def self.ignored_modules
[307] Fix | Delete
# We could cache the result, but this is very fast already.
[308] Fix | Delete
# By using this approach, we avoid Module#name calls, which are
[309] Fix | Delete
# relatively slow when there are a lot of anonymous modules defined.
[310] Fix | Delete
s = {}
[311] Fix | Delete
[312] Fix | Delete
scanner = lambda do |m|
[313] Fix | Delete
next if s.include?(m) # IRB::ExtendCommandBundle::EXCB recurses.
[314] Fix | Delete
s[m] = true
[315] Fix | Delete
m.constants(false).each do |c|
[316] Fix | Delete
value = m.const_get(c)
[317] Fix | Delete
scanner.call(value) if value.is_a?(Module)
[318] Fix | Delete
end
[319] Fix | Delete
end
[320] Fix | Delete
[321] Fix | Delete
%i(IRB RubyLex).each do |sym|
[322] Fix | Delete
next unless Object.const_defined?(sym)
[323] Fix | Delete
scanner.call(Object.const_get(sym))
[324] Fix | Delete
end
[325] Fix | Delete
[326] Fix | Delete
s.delete(IRB::Context) if defined?(IRB::Context)
[327] Fix | Delete
[328] Fix | Delete
s
[329] Fix | Delete
end
[330] Fix | Delete
end
[331] Fix | Delete
end
[332] Fix | Delete
[333] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function