Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby27/share/ruby/irb
File: context.rb
# frozen_string_literal: false
[0] Fix | Delete
#
[1] Fix | Delete
# irb/context.rb - irb context
[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
require_relative "workspace"
[11] Fix | Delete
require_relative "inspector"
[12] Fix | Delete
require_relative "input-method"
[13] Fix | Delete
require_relative "output-method"
[14] Fix | Delete
[15] Fix | Delete
module IRB
[16] Fix | Delete
# A class that wraps the current state of the irb session, including the
[17] Fix | Delete
# configuration of IRB.conf.
[18] Fix | Delete
class Context
[19] Fix | Delete
# Creates a new IRB context.
[20] Fix | Delete
#
[21] Fix | Delete
# The optional +input_method+ argument:
[22] Fix | Delete
#
[23] Fix | Delete
# +nil+:: uses stdin or Reidline or Readline
[24] Fix | Delete
# +String+:: uses a File
[25] Fix | Delete
# +other+:: uses this as InputMethod
[26] Fix | Delete
def initialize(irb, workspace = nil, input_method = nil)
[27] Fix | Delete
@irb = irb
[28] Fix | Delete
if workspace
[29] Fix | Delete
@workspace = workspace
[30] Fix | Delete
else
[31] Fix | Delete
@workspace = WorkSpace.new
[32] Fix | Delete
end
[33] Fix | Delete
@thread = Thread.current if defined? Thread
[34] Fix | Delete
[35] Fix | Delete
# copy of default configuration
[36] Fix | Delete
@ap_name = IRB.conf[:AP_NAME]
[37] Fix | Delete
@rc = IRB.conf[:RC]
[38] Fix | Delete
@load_modules = IRB.conf[:LOAD_MODULES]
[39] Fix | Delete
[40] Fix | Delete
if IRB.conf.has_key?(:USE_SINGLELINE)
[41] Fix | Delete
@use_singleline = IRB.conf[:USE_SINGLELINE]
[42] Fix | Delete
elsif IRB.conf.has_key?(:USE_READLINE) # backward compatibility
[43] Fix | Delete
@use_singleline = IRB.conf[:USE_READLINE]
[44] Fix | Delete
else
[45] Fix | Delete
@use_singleline = nil
[46] Fix | Delete
end
[47] Fix | Delete
if IRB.conf.has_key?(:USE_MULTILINE)
[48] Fix | Delete
@use_multiline = IRB.conf[:USE_MULTILINE]
[49] Fix | Delete
elsif IRB.conf.has_key?(:USE_REIDLINE) # backward compatibility
[50] Fix | Delete
@use_multiline = IRB.conf[:USE_REIDLINE]
[51] Fix | Delete
else
[52] Fix | Delete
@use_multiline = nil
[53] Fix | Delete
end
[54] Fix | Delete
@use_colorize = IRB.conf[:USE_COLORIZE]
[55] Fix | Delete
@verbose = IRB.conf[:VERBOSE]
[56] Fix | Delete
@io = nil
[57] Fix | Delete
[58] Fix | Delete
self.inspect_mode = IRB.conf[:INSPECT_MODE]
[59] Fix | Delete
self.use_tracer = IRB.conf[:USE_TRACER] if IRB.conf[:USE_TRACER]
[60] Fix | Delete
self.use_loader = IRB.conf[:USE_LOADER] if IRB.conf[:USE_LOADER]
[61] Fix | Delete
self.eval_history = IRB.conf[:EVAL_HISTORY] if IRB.conf[:EVAL_HISTORY]
[62] Fix | Delete
[63] Fix | Delete
@ignore_sigint = IRB.conf[:IGNORE_SIGINT]
[64] Fix | Delete
@ignore_eof = IRB.conf[:IGNORE_EOF]
[65] Fix | Delete
[66] Fix | Delete
@back_trace_limit = IRB.conf[:BACK_TRACE_LIMIT]
[67] Fix | Delete
[68] Fix | Delete
self.prompt_mode = IRB.conf[:PROMPT_MODE]
[69] Fix | Delete
[70] Fix | Delete
if IRB.conf[:SINGLE_IRB] or !defined?(IRB::JobManager)
[71] Fix | Delete
@irb_name = IRB.conf[:IRB_NAME]
[72] Fix | Delete
else
[73] Fix | Delete
@irb_name = IRB.conf[:IRB_NAME]+"#"+IRB.JobManager.n_jobs.to_s
[74] Fix | Delete
end
[75] Fix | Delete
@irb_path = "(" + @irb_name + ")"
[76] Fix | Delete
[77] Fix | Delete
case input_method
[78] Fix | Delete
when nil
[79] Fix | Delete
@io = nil
[80] Fix | Delete
case use_multiline?
[81] Fix | Delete
when nil
[82] Fix | Delete
if STDIN.tty? && IRB.conf[:PROMPT_MODE] != :INF_RUBY && !use_singleline?
[83] Fix | Delete
# Both of multiline mode and singleline mode aren't specified.
[84] Fix | Delete
@io = ReidlineInputMethod.new
[85] Fix | Delete
else
[86] Fix | Delete
@io = nil
[87] Fix | Delete
end
[88] Fix | Delete
when false
[89] Fix | Delete
@io = nil
[90] Fix | Delete
when true
[91] Fix | Delete
@io = ReidlineInputMethod.new
[92] Fix | Delete
end
[93] Fix | Delete
unless @io
[94] Fix | Delete
case use_singleline?
[95] Fix | Delete
when nil
[96] Fix | Delete
if (defined?(ReadlineInputMethod) && STDIN.tty? &&
[97] Fix | Delete
IRB.conf[:PROMPT_MODE] != :INF_RUBY)
[98] Fix | Delete
@io = ReadlineInputMethod.new
[99] Fix | Delete
else
[100] Fix | Delete
@io = nil
[101] Fix | Delete
end
[102] Fix | Delete
when false
[103] Fix | Delete
@io = nil
[104] Fix | Delete
when true
[105] Fix | Delete
if defined?(ReadlineInputMethod)
[106] Fix | Delete
@io = ReadlineInputMethod.new
[107] Fix | Delete
else
[108] Fix | Delete
@io = nil
[109] Fix | Delete
end
[110] Fix | Delete
else
[111] Fix | Delete
@io = nil
[112] Fix | Delete
end
[113] Fix | Delete
end
[114] Fix | Delete
@io = StdioInputMethod.new unless @io
[115] Fix | Delete
[116] Fix | Delete
when String
[117] Fix | Delete
@io = FileInputMethod.new(input_method)
[118] Fix | Delete
@irb_name = File.basename(input_method)
[119] Fix | Delete
@irb_path = input_method
[120] Fix | Delete
else
[121] Fix | Delete
@io = input_method
[122] Fix | Delete
end
[123] Fix | Delete
self.save_history = IRB.conf[:SAVE_HISTORY] if IRB.conf[:SAVE_HISTORY]
[124] Fix | Delete
[125] Fix | Delete
@echo = IRB.conf[:ECHO]
[126] Fix | Delete
if @echo.nil?
[127] Fix | Delete
@echo = true
[128] Fix | Delete
end
[129] Fix | Delete
[130] Fix | Delete
@echo_on_assignment = IRB.conf[:ECHO_ON_ASSIGNMENT]
[131] Fix | Delete
if @echo_on_assignment.nil?
[132] Fix | Delete
@echo_on_assignment = true
[133] Fix | Delete
end
[134] Fix | Delete
[135] Fix | Delete
@omit_on_assignment = IRB.conf[:OMIT_ON_ASSIGNMENT]
[136] Fix | Delete
if @omit_on_assignment.nil?
[137] Fix | Delete
@omit_on_assignment = true
[138] Fix | Delete
end
[139] Fix | Delete
[140] Fix | Delete
@newline_before_multiline_output = IRB.conf[:NEWLINE_BEFORE_MULTILINE_OUTPUT]
[141] Fix | Delete
if @newline_before_multiline_output.nil?
[142] Fix | Delete
@newline_before_multiline_output = true
[143] Fix | Delete
end
[144] Fix | Delete
end
[145] Fix | Delete
[146] Fix | Delete
# The top-level workspace, see WorkSpace#main
[147] Fix | Delete
def main
[148] Fix | Delete
@workspace.main
[149] Fix | Delete
end
[150] Fix | Delete
[151] Fix | Delete
# The toplevel workspace, see #home_workspace
[152] Fix | Delete
attr_reader :workspace_home
[153] Fix | Delete
# WorkSpace in the current context
[154] Fix | Delete
attr_accessor :workspace
[155] Fix | Delete
# The current thread in this context
[156] Fix | Delete
attr_reader :thread
[157] Fix | Delete
# The current input method
[158] Fix | Delete
#
[159] Fix | Delete
# Can be either StdioInputMethod, ReadlineInputMethod,
[160] Fix | Delete
# ReidlineInputMethod, FileInputMethod or other specified when the
[161] Fix | Delete
# context is created. See ::new for more # information on +input_method+.
[162] Fix | Delete
attr_accessor :io
[163] Fix | Delete
[164] Fix | Delete
# Current irb session
[165] Fix | Delete
attr_accessor :irb
[166] Fix | Delete
# A copy of the default <code>IRB.conf[:AP_NAME]</code>
[167] Fix | Delete
attr_accessor :ap_name
[168] Fix | Delete
# A copy of the default <code>IRB.conf[:RC]</code>
[169] Fix | Delete
attr_accessor :rc
[170] Fix | Delete
# A copy of the default <code>IRB.conf[:LOAD_MODULES]</code>
[171] Fix | Delete
attr_accessor :load_modules
[172] Fix | Delete
# Can be either name from <code>IRB.conf[:IRB_NAME]</code>, or the number of
[173] Fix | Delete
# the current job set by JobManager, such as <code>irb#2</code>
[174] Fix | Delete
attr_accessor :irb_name
[175] Fix | Delete
# Can be either the #irb_name surrounded by parenthesis, or the
[176] Fix | Delete
# +input_method+ passed to Context.new
[177] Fix | Delete
attr_accessor :irb_path
[178] Fix | Delete
[179] Fix | Delete
# Whether multiline editor mode is enabled or not.
[180] Fix | Delete
#
[181] Fix | Delete
# A copy of the default <code>IRB.conf[:USE_MULTILINE]</code>
[182] Fix | Delete
attr_reader :use_multiline
[183] Fix | Delete
# Whether singleline editor mode is enabled or not.
[184] Fix | Delete
#
[185] Fix | Delete
# A copy of the default <code>IRB.conf[:USE_SINGLELINE]</code>
[186] Fix | Delete
attr_reader :use_singleline
[187] Fix | Delete
# Whether colorization is enabled or not.
[188] Fix | Delete
#
[189] Fix | Delete
# A copy of the default <code>IRB.conf[:USE_COLORIZE]</code>
[190] Fix | Delete
attr_reader :use_colorize
[191] Fix | Delete
# A copy of the default <code>IRB.conf[:INSPECT_MODE]</code>
[192] Fix | Delete
attr_reader :inspect_mode
[193] Fix | Delete
[194] Fix | Delete
# A copy of the default <code>IRB.conf[:PROMPT_MODE]</code>
[195] Fix | Delete
attr_reader :prompt_mode
[196] Fix | Delete
# Standard IRB prompt
[197] Fix | Delete
#
[198] Fix | Delete
# See IRB@Customizing+the+IRB+Prompt for more information.
[199] Fix | Delete
attr_accessor :prompt_i
[200] Fix | Delete
# IRB prompt for continuated strings
[201] Fix | Delete
#
[202] Fix | Delete
# See IRB@Customizing+the+IRB+Prompt for more information.
[203] Fix | Delete
attr_accessor :prompt_s
[204] Fix | Delete
# IRB prompt for continuated statement (e.g. immediately after an +if+)
[205] Fix | Delete
#
[206] Fix | Delete
# See IRB@Customizing+the+IRB+Prompt for more information.
[207] Fix | Delete
attr_accessor :prompt_c
[208] Fix | Delete
# See IRB@Customizing+the+IRB+Prompt for more information.
[209] Fix | Delete
attr_accessor :prompt_n
[210] Fix | Delete
# Can be either the default <code>IRB.conf[:AUTO_INDENT]</code>, or the
[211] Fix | Delete
# mode set by #prompt_mode=
[212] Fix | Delete
#
[213] Fix | Delete
# To disable auto-indentation in irb:
[214] Fix | Delete
#
[215] Fix | Delete
# IRB.conf[:AUTO_INDENT] = false
[216] Fix | Delete
#
[217] Fix | Delete
# or
[218] Fix | Delete
#
[219] Fix | Delete
# irb_context.auto_indent_mode = false
[220] Fix | Delete
#
[221] Fix | Delete
# or
[222] Fix | Delete
#
[223] Fix | Delete
# IRB.CurrentContext.auto_indent_mode = false
[224] Fix | Delete
#
[225] Fix | Delete
# See IRB@Configuration for more information.
[226] Fix | Delete
attr_accessor :auto_indent_mode
[227] Fix | Delete
# The format of the return statement, set by #prompt_mode= using the
[228] Fix | Delete
# +:RETURN+ of the +mode+ passed to set the current #prompt_mode.
[229] Fix | Delete
attr_accessor :return_format
[230] Fix | Delete
[231] Fix | Delete
# Whether <code>^C</code> (+control-c+) will be ignored or not.
[232] Fix | Delete
#
[233] Fix | Delete
# If set to +false+, <code>^C</code> will quit irb.
[234] Fix | Delete
#
[235] Fix | Delete
# If set to +true+,
[236] Fix | Delete
#
[237] Fix | Delete
# * during input: cancel input then return to top level.
[238] Fix | Delete
# * during execute: abandon current execution.
[239] Fix | Delete
attr_accessor :ignore_sigint
[240] Fix | Delete
# Whether <code>^D</code> (+control-d+) will be ignored or not.
[241] Fix | Delete
#
[242] Fix | Delete
# If set to +false+, <code>^D</code> will quit irb.
[243] Fix | Delete
attr_accessor :ignore_eof
[244] Fix | Delete
# Whether to echo the return value to output or not.
[245] Fix | Delete
#
[246] Fix | Delete
# Uses <code>IRB.conf[:ECHO]</code> if available, or defaults to +true+.
[247] Fix | Delete
#
[248] Fix | Delete
# puts "hello"
[249] Fix | Delete
# # hello
[250] Fix | Delete
# #=> nil
[251] Fix | Delete
# IRB.CurrentContext.echo = false
[252] Fix | Delete
# puts "omg"
[253] Fix | Delete
# # omg
[254] Fix | Delete
attr_accessor :echo
[255] Fix | Delete
# Whether to echo for assignment expressions
[256] Fix | Delete
#
[257] Fix | Delete
# Uses <code>IRB.conf[:ECHO_ON_ASSIGNMENT]</code> if available, or defaults to +true+.
[258] Fix | Delete
#
[259] Fix | Delete
# a = "omg"
[260] Fix | Delete
# #=> omg
[261] Fix | Delete
# IRB.CurrentContext.echo_on_assignment = false
[262] Fix | Delete
# a = "omg"
[263] Fix | Delete
attr_accessor :echo_on_assignment
[264] Fix | Delete
# Whether to omit echo for assignment expressions
[265] Fix | Delete
#
[266] Fix | Delete
# Uses <code>IRB.conf[:OMIT_ON_ASSIGNMENT]</code> if available, or defaults to +true+.
[267] Fix | Delete
#
[268] Fix | Delete
# a = [1] * 10
[269] Fix | Delete
# #=> [1, 1, 1, 1, 1, 1, 1, 1, ...
[270] Fix | Delete
# [1] * 10
[271] Fix | Delete
# #=> [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
[272] Fix | Delete
# IRB.CurrentContext.omit_on_assignment = false
[273] Fix | Delete
# a = [1] * 10
[274] Fix | Delete
# #=> [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
[275] Fix | Delete
# [1] * 10
[276] Fix | Delete
# #=> [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
[277] Fix | Delete
attr_accessor :omit_on_assignment
[278] Fix | Delete
# Whether a newline is put before multiline output.
[279] Fix | Delete
#
[280] Fix | Delete
# Uses <code>IRB.conf[:NEWLINE_BEFORE_MULTILINE_OUTPUT]</code> if available,
[281] Fix | Delete
# or defaults to +true+.
[282] Fix | Delete
#
[283] Fix | Delete
# "abc\ndef"
[284] Fix | Delete
# #=>
[285] Fix | Delete
# abc
[286] Fix | Delete
# def
[287] Fix | Delete
# IRB.CurrentContext.newline_before_multiline_output = false
[288] Fix | Delete
# "abc\ndef"
[289] Fix | Delete
# #=> abc
[290] Fix | Delete
# def
[291] Fix | Delete
attr_accessor :newline_before_multiline_output
[292] Fix | Delete
# Whether verbose messages are displayed or not.
[293] Fix | Delete
#
[294] Fix | Delete
# A copy of the default <code>IRB.conf[:VERBOSE]</code>
[295] Fix | Delete
attr_accessor :verbose
[296] Fix | Delete
[297] Fix | Delete
# The limit of backtrace lines displayed as top +n+ and tail +n+.
[298] Fix | Delete
#
[299] Fix | Delete
# The default value is 16.
[300] Fix | Delete
#
[301] Fix | Delete
# Can also be set using the +--back-trace-limit+ command line option.
[302] Fix | Delete
#
[303] Fix | Delete
# See IRB@Command+line+options for more command line options.
[304] Fix | Delete
attr_accessor :back_trace_limit
[305] Fix | Delete
[306] Fix | Delete
# Alias for #use_multiline
[307] Fix | Delete
alias use_multiline? use_multiline
[308] Fix | Delete
# Alias for #use_singleline
[309] Fix | Delete
alias use_singleline? use_singleline
[310] Fix | Delete
# backward compatibility
[311] Fix | Delete
alias use_reidline use_multiline
[312] Fix | Delete
# backward compatibility
[313] Fix | Delete
alias use_reidline? use_multiline
[314] Fix | Delete
# backward compatibility
[315] Fix | Delete
alias use_readline use_singleline
[316] Fix | Delete
# backward compatibility
[317] Fix | Delete
alias use_readline? use_singleline
[318] Fix | Delete
# Alias for #use_colorize
[319] Fix | Delete
alias use_colorize? use_colorize
[320] Fix | Delete
# Alias for #rc
[321] Fix | Delete
alias rc? rc
[322] Fix | Delete
alias ignore_sigint? ignore_sigint
[323] Fix | Delete
alias ignore_eof? ignore_eof
[324] Fix | Delete
alias echo? echo
[325] Fix | Delete
alias echo_on_assignment? echo_on_assignment
[326] Fix | Delete
alias omit_on_assignment? omit_on_assignment
[327] Fix | Delete
alias newline_before_multiline_output? newline_before_multiline_output
[328] Fix | Delete
[329] Fix | Delete
# Returns whether messages are displayed or not.
[330] Fix | Delete
def verbose?
[331] Fix | Delete
if @verbose.nil?
[332] Fix | Delete
if @io.kind_of?(ReidlineInputMethod)
[333] Fix | Delete
false
[334] Fix | Delete
elsif defined?(ReadlineInputMethod) && @io.kind_of?(ReadlineInputMethod)
[335] Fix | Delete
false
[336] Fix | Delete
elsif !STDIN.tty? or @io.kind_of?(FileInputMethod)
[337] Fix | Delete
true
[338] Fix | Delete
else
[339] Fix | Delete
false
[340] Fix | Delete
end
[341] Fix | Delete
else
[342] Fix | Delete
@verbose
[343] Fix | Delete
end
[344] Fix | Delete
end
[345] Fix | Delete
[346] Fix | Delete
# Whether #verbose? is +true+, and +input_method+ is either
[347] Fix | Delete
# StdioInputMethod or ReidlineInputMethod or ReadlineInputMethod, see #io
[348] Fix | Delete
# for more information.
[349] Fix | Delete
def prompting?
[350] Fix | Delete
verbose? || (STDIN.tty? && @io.kind_of?(StdioInputMethod) ||
[351] Fix | Delete
@io.kind_of?(ReidlineInputMethod) ||
[352] Fix | Delete
(defined?(ReadlineInputMethod) && @io.kind_of?(ReadlineInputMethod)))
[353] Fix | Delete
end
[354] Fix | Delete
[355] Fix | Delete
# The return value of the last statement evaluated.
[356] Fix | Delete
attr_reader :last_value
[357] Fix | Delete
[358] Fix | Delete
# Sets the return value from the last statement evaluated in this context
[359] Fix | Delete
# to #last_value.
[360] Fix | Delete
def set_last_value(value)
[361] Fix | Delete
@last_value = value
[362] Fix | Delete
@workspace.local_variable_set :_, value
[363] Fix | Delete
end
[364] Fix | Delete
[365] Fix | Delete
# Sets the +mode+ of the prompt in this context.
[366] Fix | Delete
#
[367] Fix | Delete
# See IRB@Customizing+the+IRB+Prompt for more information.
[368] Fix | Delete
def prompt_mode=(mode)
[369] Fix | Delete
@prompt_mode = mode
[370] Fix | Delete
pconf = IRB.conf[:PROMPT][mode]
[371] Fix | Delete
@prompt_i = pconf[:PROMPT_I]
[372] Fix | Delete
@prompt_s = pconf[:PROMPT_S]
[373] Fix | Delete
@prompt_c = pconf[:PROMPT_C]
[374] Fix | Delete
@prompt_n = pconf[:PROMPT_N]
[375] Fix | Delete
@return_format = pconf[:RETURN]
[376] Fix | Delete
if ai = pconf.include?(:AUTO_INDENT)
[377] Fix | Delete
@auto_indent_mode = ai
[378] Fix | Delete
else
[379] Fix | Delete
@auto_indent_mode = IRB.conf[:AUTO_INDENT]
[380] Fix | Delete
end
[381] Fix | Delete
end
[382] Fix | Delete
[383] Fix | Delete
# Whether #inspect_mode is set or not, see #inspect_mode= for more detail.
[384] Fix | Delete
def inspect?
[385] Fix | Delete
@inspect_mode.nil? or @inspect_mode
[386] Fix | Delete
end
[387] Fix | Delete
[388] Fix | Delete
# Whether #io uses a File for the +input_method+ passed when creating the
[389] Fix | Delete
# current context, see ::new
[390] Fix | Delete
def file_input?
[391] Fix | Delete
@io.class == FileInputMethod
[392] Fix | Delete
end
[393] Fix | Delete
[394] Fix | Delete
# Specifies the inspect mode with +opt+:
[395] Fix | Delete
#
[396] Fix | Delete
# +true+:: display +inspect+
[397] Fix | Delete
# +false+:: display +to_s+
[398] Fix | Delete
# +nil+:: inspect mode in non-math mode,
[399] Fix | Delete
# non-inspect mode in math mode
[400] Fix | Delete
#
[401] Fix | Delete
# See IRB::Inspector for more information.
[402] Fix | Delete
#
[403] Fix | Delete
# Can also be set using the +--inspect+ and +--noinspect+ command line
[404] Fix | Delete
# options.
[405] Fix | Delete
#
[406] Fix | Delete
# See IRB@Command+line+options for more command line options.
[407] Fix | Delete
def inspect_mode=(opt)
[408] Fix | Delete
[409] Fix | Delete
if i = Inspector::INSPECTORS[opt]
[410] Fix | Delete
@inspect_mode = opt
[411] Fix | Delete
@inspect_method = i
[412] Fix | Delete
i.init
[413] Fix | Delete
else
[414] Fix | Delete
case opt
[415] Fix | Delete
when nil
[416] Fix | Delete
if Inspector.keys_with_inspector(Inspector::INSPECTORS[true]).include?(@inspect_mode)
[417] Fix | Delete
self.inspect_mode = false
[418] Fix | Delete
elsif Inspector.keys_with_inspector(Inspector::INSPECTORS[false]).include?(@inspect_mode)
[419] Fix | Delete
self.inspect_mode = true
[420] Fix | Delete
else
[421] Fix | Delete
puts "Can't switch inspect mode."
[422] Fix | Delete
return
[423] Fix | Delete
end
[424] Fix | Delete
when /^\s*\{.*\}\s*$/
[425] Fix | Delete
begin
[426] Fix | Delete
inspector = eval "proc#{opt}"
[427] Fix | Delete
rescue Exception
[428] Fix | Delete
puts "Can't switch inspect mode(#{opt})."
[429] Fix | Delete
return
[430] Fix | Delete
end
[431] Fix | Delete
self.inspect_mode = inspector
[432] Fix | Delete
when Proc
[433] Fix | Delete
self.inspect_mode = IRB::Inspector(opt)
[434] Fix | Delete
when Inspector
[435] Fix | Delete
prefix = "usr%d"
[436] Fix | Delete
i = 1
[437] Fix | Delete
while Inspector::INSPECTORS[format(prefix, i)]; i += 1; end
[438] Fix | Delete
@inspect_mode = format(prefix, i)
[439] Fix | Delete
@inspect_method = opt
[440] Fix | Delete
Inspector.def_inspector(format(prefix, i), @inspect_method)
[441] Fix | Delete
else
[442] Fix | Delete
puts "Can't switch inspect mode(#{opt})."
[443] Fix | Delete
return
[444] Fix | Delete
end
[445] Fix | Delete
end
[446] Fix | Delete
print "Switch to#{unless @inspect_mode; ' non';end} inspect mode.\n" if verbose?
[447] Fix | Delete
@inspect_mode
[448] Fix | Delete
end
[449] Fix | Delete
[450] Fix | Delete
def evaluate(line, line_no, exception: nil) # :nodoc:
[451] Fix | Delete
@line_no = line_no
[452] Fix | Delete
if exception
[453] Fix | Delete
line_no -= 1
[454] Fix | Delete
line = "begin ::Kernel.raise _; rescue _.class\n#{line}\n""end"
[455] Fix | Delete
@workspace.local_variable_set(:_, exception)
[456] Fix | Delete
end
[457] Fix | Delete
set_last_value(@workspace.evaluate(self, line, irb_path, line_no))
[458] Fix | Delete
end
[459] Fix | Delete
[460] Fix | Delete
def inspect_last_value # :nodoc:
[461] Fix | Delete
@inspect_method.inspect_value(@last_value)
[462] Fix | Delete
end
[463] Fix | Delete
[464] Fix | Delete
alias __exit__ exit
[465] Fix | Delete
# Exits the current session, see IRB.irb_exit
[466] Fix | Delete
def exit(ret = 0)
[467] Fix | Delete
IRB.irb_exit(@irb, ret)
[468] Fix | Delete
end
[469] Fix | Delete
[470] Fix | Delete
NOPRINTING_IVARS = ["@last_value"] # :nodoc:
[471] Fix | Delete
NO_INSPECTING_IVARS = ["@irb", "@io"] # :nodoc:
[472] Fix | Delete
IDNAME_IVARS = ["@prompt_mode"] # :nodoc:
[473] Fix | Delete
[474] Fix | Delete
alias __inspect__ inspect
[475] Fix | Delete
def inspect # :nodoc:
[476] Fix | Delete
array = []
[477] Fix | Delete
for ivar in instance_variables.sort{|e1, e2| e1 <=> e2}
[478] Fix | Delete
ivar = ivar.to_s
[479] Fix | Delete
name = ivar.sub(/^@(.*)$/, '\1')
[480] Fix | Delete
val = instance_eval(ivar)
[481] Fix | Delete
case ivar
[482] Fix | Delete
when *NOPRINTING_IVARS
[483] Fix | Delete
array.push format("conf.%s=%s", name, "...")
[484] Fix | Delete
when *NO_INSPECTING_IVARS
[485] Fix | Delete
array.push format("conf.%s=%s", name, val.to_s)
[486] Fix | Delete
when *IDNAME_IVARS
[487] Fix | Delete
array.push format("conf.%s=:%s", name, val.id2name)
[488] Fix | Delete
else
[489] Fix | Delete
array.push format("conf.%s=%s", name, val.inspect)
[490] Fix | Delete
end
[491] Fix | Delete
end
[492] Fix | Delete
array.join("\n")
[493] Fix | Delete
end
[494] Fix | Delete
alias __to_s__ to_s
[495] Fix | Delete
alias to_s inspect
[496] Fix | Delete
end
[497] Fix | Delete
end
[498] Fix | Delete
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function