Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby27/share/ruby/irb
File: workspace.rb
# frozen_string_literal: false
[0] Fix | Delete
#
[1] Fix | Delete
# irb/workspace-binding.rb -
[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
[11] Fix | Delete
require "delegate"
[12] Fix | Delete
[13] Fix | Delete
module IRB # :nodoc:
[14] Fix | Delete
class WorkSpace
[15] Fix | Delete
# Creates a new workspace.
[16] Fix | Delete
#
[17] Fix | Delete
# set self to main if specified, otherwise
[18] Fix | Delete
# inherit main from TOPLEVEL_BINDING.
[19] Fix | Delete
def initialize(*main)
[20] Fix | Delete
if main[0].kind_of?(Binding)
[21] Fix | Delete
@binding = main.shift
[22] Fix | Delete
elsif IRB.conf[:SINGLE_IRB]
[23] Fix | Delete
@binding = TOPLEVEL_BINDING
[24] Fix | Delete
else
[25] Fix | Delete
case IRB.conf[:CONTEXT_MODE]
[26] Fix | Delete
when 0 # binding in proc on TOPLEVEL_BINDING
[27] Fix | Delete
@binding = eval("proc{binding}.call",
[28] Fix | Delete
TOPLEVEL_BINDING,
[29] Fix | Delete
__FILE__,
[30] Fix | Delete
__LINE__)
[31] Fix | Delete
when 1 # binding in loaded file
[32] Fix | Delete
require "tempfile"
[33] Fix | Delete
f = Tempfile.open("irb-binding")
[34] Fix | Delete
f.print <<EOF
[35] Fix | Delete
$binding = binding
[36] Fix | Delete
EOF
[37] Fix | Delete
f.close
[38] Fix | Delete
load f.path
[39] Fix | Delete
@binding = $binding
[40] Fix | Delete
[41] Fix | Delete
when 2 # binding in loaded file(thread use)
[42] Fix | Delete
unless defined? BINDING_QUEUE
[43] Fix | Delete
IRB.const_set(:BINDING_QUEUE, Thread::SizedQueue.new(1))
[44] Fix | Delete
Thread.abort_on_exception = true
[45] Fix | Delete
Thread.start do
[46] Fix | Delete
eval "require \"irb/ws-for-case-2\"", TOPLEVEL_BINDING, __FILE__, __LINE__
[47] Fix | Delete
end
[48] Fix | Delete
Thread.pass
[49] Fix | Delete
end
[50] Fix | Delete
@binding = BINDING_QUEUE.pop
[51] Fix | Delete
[52] Fix | Delete
when 3 # binding in function on TOPLEVEL_BINDING(default)
[53] Fix | Delete
@binding = eval("self.class.send(:remove_method, :irb_binding) if defined?(irb_binding); private; def irb_binding; binding; end; irb_binding",
[54] Fix | Delete
TOPLEVEL_BINDING,
[55] Fix | Delete
__FILE__,
[56] Fix | Delete
__LINE__ - 3)
[57] Fix | Delete
end
[58] Fix | Delete
end
[59] Fix | Delete
[60] Fix | Delete
if main.empty?
[61] Fix | Delete
@main = eval("self", @binding)
[62] Fix | Delete
else
[63] Fix | Delete
@main = main[0]
[64] Fix | Delete
end
[65] Fix | Delete
IRB.conf[:__MAIN__] = @main
[66] Fix | Delete
[67] Fix | Delete
unless main.empty?
[68] Fix | Delete
case @main
[69] Fix | Delete
when Module
[70] Fix | Delete
@binding = eval("IRB.conf[:__MAIN__].module_eval('binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__)
[71] Fix | Delete
else
[72] Fix | Delete
begin
[73] Fix | Delete
@binding = eval("IRB.conf[:__MAIN__].instance_eval('binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__)
[74] Fix | Delete
rescue TypeError
[75] Fix | Delete
fail CantChangeBinding, @main.inspect
[76] Fix | Delete
end
[77] Fix | Delete
end
[78] Fix | Delete
end
[79] Fix | Delete
[80] Fix | Delete
case @main
[81] Fix | Delete
when Object
[82] Fix | Delete
use_delegator = @main.frozen?
[83] Fix | Delete
else
[84] Fix | Delete
use_delegator = true
[85] Fix | Delete
end
[86] Fix | Delete
[87] Fix | Delete
if use_delegator
[88] Fix | Delete
@main = SimpleDelegator.new(@main)
[89] Fix | Delete
IRB.conf[:__MAIN__] = @main
[90] Fix | Delete
@main.singleton_class.class_eval do
[91] Fix | Delete
private
[92] Fix | Delete
define_method(:exit) do |*a, &b|
[93] Fix | Delete
# Do nothing, will be overridden
[94] Fix | Delete
end
[95] Fix | Delete
define_method(:binding, Kernel.instance_method(:binding))
[96] Fix | Delete
define_method(:local_variables, Kernel.instance_method(:local_variables))
[97] Fix | Delete
end
[98] Fix | Delete
@binding = eval("IRB.conf[:__MAIN__].instance_eval('binding', __FILE__, __LINE__)", @binding, *@binding.source_location)
[99] Fix | Delete
end
[100] Fix | Delete
[101] Fix | Delete
@binding.local_variable_set(:_, nil)
[102] Fix | Delete
end
[103] Fix | Delete
[104] Fix | Delete
# The Binding of this workspace
[105] Fix | Delete
attr_reader :binding
[106] Fix | Delete
# The top-level workspace of this context, also available as
[107] Fix | Delete
# <code>IRB.conf[:__MAIN__]</code>
[108] Fix | Delete
attr_reader :main
[109] Fix | Delete
[110] Fix | Delete
# Evaluate the given +statements+ within the context of this workspace.
[111] Fix | Delete
def evaluate(context, statements, file = __FILE__, line = __LINE__)
[112] Fix | Delete
eval(statements, @binding, file, line)
[113] Fix | Delete
end
[114] Fix | Delete
[115] Fix | Delete
def local_variable_set(name, value)
[116] Fix | Delete
@binding.local_variable_set(name, value)
[117] Fix | Delete
end
[118] Fix | Delete
[119] Fix | Delete
def local_variable_get(name)
[120] Fix | Delete
@binding.local_variable_get(name)
[121] Fix | Delete
end
[122] Fix | Delete
[123] Fix | Delete
# error message manipulator
[124] Fix | Delete
def filter_backtrace(bt)
[125] Fix | Delete
return nil if bt =~ /\/irb\/.*\.rb/
[126] Fix | Delete
return nil if bt =~ /\/irb\.rb/
[127] Fix | Delete
case IRB.conf[:CONTEXT_MODE]
[128] Fix | Delete
when 1
[129] Fix | Delete
return nil if bt =~ %r!/tmp/irb-binding!
[130] Fix | Delete
when 3
[131] Fix | Delete
bt = bt.sub(/:\s*in `irb_binding'/, '')
[132] Fix | Delete
end
[133] Fix | Delete
bt
[134] Fix | Delete
end
[135] Fix | Delete
[136] Fix | Delete
def code_around_binding
[137] Fix | Delete
if @binding.respond_to?(:source_location)
[138] Fix | Delete
file, pos = @binding.source_location
[139] Fix | Delete
else
[140] Fix | Delete
file, pos = @binding.eval('[__FILE__, __LINE__]')
[141] Fix | Delete
end
[142] Fix | Delete
[143] Fix | Delete
if defined?(::SCRIPT_LINES__[file]) && lines = ::SCRIPT_LINES__[file]
[144] Fix | Delete
code = ::SCRIPT_LINES__[file].join('')
[145] Fix | Delete
else
[146] Fix | Delete
begin
[147] Fix | Delete
code = File.read(file)
[148] Fix | Delete
rescue SystemCallError
[149] Fix | Delete
return
[150] Fix | Delete
end
[151] Fix | Delete
end
[152] Fix | Delete
[153] Fix | Delete
# NOT using #use_colorize? of IRB.conf[:MAIN_CONTEXT] because this method may be called before IRB::Irb#run
[154] Fix | Delete
use_colorize = IRB.conf.fetch(:USE_COLORIZE, true)
[155] Fix | Delete
if use_colorize
[156] Fix | Delete
lines = Color.colorize_code(code).lines
[157] Fix | Delete
else
[158] Fix | Delete
lines = code.lines
[159] Fix | Delete
end
[160] Fix | Delete
pos -= 1
[161] Fix | Delete
[162] Fix | Delete
start_pos = [pos - 5, 0].max
[163] Fix | Delete
end_pos = [pos + 5, lines.size - 1].min
[164] Fix | Delete
[165] Fix | Delete
if use_colorize
[166] Fix | Delete
fmt = " %2s #{Color.colorize("%#{end_pos.to_s.length}d", [:BLUE, :BOLD])}: %s"
[167] Fix | Delete
else
[168] Fix | Delete
fmt = " %2s %#{end_pos.to_s.length}d: %s"
[169] Fix | Delete
end
[170] Fix | Delete
body = (start_pos..end_pos).map do |current_pos|
[171] Fix | Delete
sprintf(fmt, pos == current_pos ? '=>' : '', current_pos + 1, lines[current_pos])
[172] Fix | Delete
end.join("")
[173] Fix | Delete
"\nFrom: #{file} @ line #{pos + 1} :\n\n#{body}#{Color.clear}\n"
[174] Fix | Delete
end
[175] Fix | Delete
[176] Fix | Delete
def IRB.delete_caller
[177] Fix | Delete
end
[178] Fix | Delete
end
[179] Fix | Delete
end
[180] Fix | Delete
[181] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function