Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby27/share/ruby/irb
File: xmp.rb
# frozen_string_literal: false
[0] Fix | Delete
#
[1] Fix | Delete
# xmp.rb - irb version of gotoken xmp
[2] Fix | Delete
# $Release Version: 0.9$
[3] Fix | Delete
# $Revision$
[4] Fix | Delete
# by Keiju ISHITSUKA(Nippon Rational Inc.)
[5] Fix | Delete
#
[6] Fix | Delete
# --
[7] Fix | Delete
#
[8] Fix | Delete
#
[9] Fix | Delete
#
[10] Fix | Delete
[11] Fix | Delete
require_relative "../irb"
[12] Fix | Delete
require_relative "frame"
[13] Fix | Delete
[14] Fix | Delete
# An example printer for irb.
[15] Fix | Delete
#
[16] Fix | Delete
# It's much like the standard library PrettyPrint, that shows the value of each
[17] Fix | Delete
# expression as it runs.
[18] Fix | Delete
#
[19] Fix | Delete
# In order to use this library, you must first require it:
[20] Fix | Delete
#
[21] Fix | Delete
# require 'irb/xmp'
[22] Fix | Delete
#
[23] Fix | Delete
# Now, you can take advantage of the Object#xmp convenience method.
[24] Fix | Delete
#
[25] Fix | Delete
# xmp <<END
[26] Fix | Delete
# foo = "bar"
[27] Fix | Delete
# baz = 42
[28] Fix | Delete
# END
[29] Fix | Delete
# #=> foo = "bar"
[30] Fix | Delete
# #==>"bar"
[31] Fix | Delete
# #=> baz = 42
[32] Fix | Delete
# #==>42
[33] Fix | Delete
#
[34] Fix | Delete
# You can also create an XMP object, with an optional binding to print
[35] Fix | Delete
# expressions in the given binding:
[36] Fix | Delete
#
[37] Fix | Delete
# ctx = binding
[38] Fix | Delete
# x = XMP.new ctx
[39] Fix | Delete
# x.puts
[40] Fix | Delete
# #=> today = "a good day"
[41] Fix | Delete
# #==>"a good day"
[42] Fix | Delete
# ctx.eval 'today # is what?'
[43] Fix | Delete
# #=> "a good day"
[44] Fix | Delete
class XMP
[45] Fix | Delete
[46] Fix | Delete
# Creates a new XMP object.
[47] Fix | Delete
#
[48] Fix | Delete
# The top-level binding or, optional +bind+ parameter will be used when
[49] Fix | Delete
# creating the workspace. See WorkSpace.new for more information.
[50] Fix | Delete
#
[51] Fix | Delete
# This uses the +:XMP+ prompt mode, see IRB@Customizing+the+IRB+Prompt for
[52] Fix | Delete
# full detail.
[53] Fix | Delete
def initialize(bind = nil)
[54] Fix | Delete
IRB.init_config(nil)
[55] Fix | Delete
[56] Fix | Delete
IRB.conf[:PROMPT_MODE] = :XMP
[57] Fix | Delete
[58] Fix | Delete
bind = IRB::Frame.top(1) unless bind
[59] Fix | Delete
ws = IRB::WorkSpace.new(bind)
[60] Fix | Delete
@io = StringInputMethod.new
[61] Fix | Delete
@irb = IRB::Irb.new(ws, @io)
[62] Fix | Delete
@irb.context.ignore_sigint = false
[63] Fix | Delete
[64] Fix | Delete
IRB.conf[:MAIN_CONTEXT] = @irb.context
[65] Fix | Delete
end
[66] Fix | Delete
[67] Fix | Delete
# Evaluates the given +exps+, for example:
[68] Fix | Delete
#
[69] Fix | Delete
# require 'irb/xmp'
[70] Fix | Delete
# x = XMP.new
[71] Fix | Delete
#
[72] Fix | Delete
# x.puts '{:a => 1, :b => 2, :c => 3}'
[73] Fix | Delete
# #=> {:a => 1, :b => 2, :c => 3}
[74] Fix | Delete
# # ==>{:a=>1, :b=>2, :c=>3}
[75] Fix | Delete
# x.puts 'foo = "bar"'
[76] Fix | Delete
# # => foo = "bar"
[77] Fix | Delete
# # ==>"bar"
[78] Fix | Delete
def puts(exps)
[79] Fix | Delete
@io.puts exps
[80] Fix | Delete
[81] Fix | Delete
if @irb.context.ignore_sigint
[82] Fix | Delete
begin
[83] Fix | Delete
trap_proc_b = trap("SIGINT"){@irb.signal_handle}
[84] Fix | Delete
catch(:IRB_EXIT) do
[85] Fix | Delete
@irb.eval_input
[86] Fix | Delete
end
[87] Fix | Delete
ensure
[88] Fix | Delete
trap("SIGINT", trap_proc_b)
[89] Fix | Delete
end
[90] Fix | Delete
else
[91] Fix | Delete
catch(:IRB_EXIT) do
[92] Fix | Delete
@irb.eval_input
[93] Fix | Delete
end
[94] Fix | Delete
end
[95] Fix | Delete
end
[96] Fix | Delete
[97] Fix | Delete
# A custom InputMethod class used by XMP for evaluating string io.
[98] Fix | Delete
class StringInputMethod < IRB::InputMethod
[99] Fix | Delete
# Creates a new StringInputMethod object
[100] Fix | Delete
def initialize
[101] Fix | Delete
super
[102] Fix | Delete
@exps = []
[103] Fix | Delete
end
[104] Fix | Delete
[105] Fix | Delete
# Whether there are any expressions left in this printer.
[106] Fix | Delete
def eof?
[107] Fix | Delete
@exps.empty?
[108] Fix | Delete
end
[109] Fix | Delete
[110] Fix | Delete
# Reads the next expression from this printer.
[111] Fix | Delete
#
[112] Fix | Delete
# See IO#gets for more information.
[113] Fix | Delete
def gets
[114] Fix | Delete
while l = @exps.shift
[115] Fix | Delete
next if /^\s+$/ =~ l
[116] Fix | Delete
l.concat "\n"
[117] Fix | Delete
print @prompt, l
[118] Fix | Delete
break
[119] Fix | Delete
end
[120] Fix | Delete
l
[121] Fix | Delete
end
[122] Fix | Delete
[123] Fix | Delete
# Concatenates all expressions in this printer, separated by newlines.
[124] Fix | Delete
#
[125] Fix | Delete
# An Encoding::CompatibilityError is raised of the given +exps+'s encoding
[126] Fix | Delete
# doesn't match the previous expression evaluated.
[127] Fix | Delete
def puts(exps)
[128] Fix | Delete
if @encoding and exps.encoding != @encoding
[129] Fix | Delete
enc = Encoding.compatible?(@exps.join("\n"), exps)
[130] Fix | Delete
if enc.nil?
[131] Fix | Delete
raise Encoding::CompatibilityError, "Encoding in which the passed expression is encoded is not compatible to the preceding's one"
[132] Fix | Delete
else
[133] Fix | Delete
@encoding = enc
[134] Fix | Delete
end
[135] Fix | Delete
else
[136] Fix | Delete
@encoding = exps.encoding
[137] Fix | Delete
end
[138] Fix | Delete
@exps.concat exps.split(/\n/)
[139] Fix | Delete
end
[140] Fix | Delete
[141] Fix | Delete
# Returns the encoding of last expression printed by #puts.
[142] Fix | Delete
attr_reader :encoding
[143] Fix | Delete
end
[144] Fix | Delete
end
[145] Fix | Delete
[146] Fix | Delete
# A convenience method that's only available when the you require the IRB::XMP standard library.
[147] Fix | Delete
#
[148] Fix | Delete
# Creates a new XMP object, using the given expressions as the +exps+
[149] Fix | Delete
# parameter, and optional binding as +bind+ or uses the top-level binding. Then
[150] Fix | Delete
# evaluates the given expressions using the +:XMP+ prompt mode.
[151] Fix | Delete
#
[152] Fix | Delete
# For example:
[153] Fix | Delete
#
[154] Fix | Delete
# require 'irb/xmp'
[155] Fix | Delete
# ctx = binding
[156] Fix | Delete
# xmp 'foo = "bar"', ctx
[157] Fix | Delete
# #=> foo = "bar"
[158] Fix | Delete
# #==>"bar"
[159] Fix | Delete
# ctx.eval 'foo'
[160] Fix | Delete
# #=> "bar"
[161] Fix | Delete
#
[162] Fix | Delete
# See XMP.new for more information.
[163] Fix | Delete
def xmp(exps, bind = nil)
[164] Fix | Delete
bind = IRB::Frame.top(1) unless bind
[165] Fix | Delete
xmp = XMP.new(bind)
[166] Fix | Delete
xmp.puts exps
[167] Fix | Delete
xmp
[168] Fix | Delete
end
[169] Fix | Delete
[170] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function