Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../proc/self/root/usr/share/ruby
File: irb.rb
# frozen_string_literal: false
[0] Fix | Delete
#
[1] Fix | Delete
# irb.rb - irb main module
[2] Fix | Delete
# $Release Version: 0.9.6 $
[3] Fix | Delete
# $Revision: 62510 $
[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 "e2mmap"
[11] Fix | Delete
[12] Fix | Delete
require "irb/init"
[13] Fix | Delete
require "irb/context"
[14] Fix | Delete
require "irb/extend-command"
[15] Fix | Delete
[16] Fix | Delete
require "irb/ruby-lex"
[17] Fix | Delete
require "irb/input-method"
[18] Fix | Delete
require "irb/locale"
[19] Fix | Delete
[20] Fix | Delete
# IRB stands for "interactive Ruby" and is a tool to interactively execute Ruby
[21] Fix | Delete
# expressions read from the standard input.
[22] Fix | Delete
#
[23] Fix | Delete
# The +irb+ command from your shell will start the interpreter.
[24] Fix | Delete
#
[25] Fix | Delete
# == Usage
[26] Fix | Delete
#
[27] Fix | Delete
# Use of irb is easy if you know Ruby.
[28] Fix | Delete
#
[29] Fix | Delete
# When executing irb, prompts are displayed as follows. Then, enter the Ruby
[30] Fix | Delete
# expression. An input is executed when it is syntactically complete.
[31] Fix | Delete
#
[32] Fix | Delete
# $ irb
[33] Fix | Delete
# irb(main):001:0> 1+2
[34] Fix | Delete
# #=> 3
[35] Fix | Delete
# irb(main):002:0> class Foo
[36] Fix | Delete
# irb(main):003:1> def foo
[37] Fix | Delete
# irb(main):004:2> print 1
[38] Fix | Delete
# irb(main):005:2> end
[39] Fix | Delete
# irb(main):006:1> end
[40] Fix | Delete
# #=> nil
[41] Fix | Delete
#
[42] Fix | Delete
# The Readline extension module can be used with irb. Use of Readline is
[43] Fix | Delete
# default if it's installed.
[44] Fix | Delete
#
[45] Fix | Delete
# == Command line options
[46] Fix | Delete
#
[47] Fix | Delete
# Usage: irb.rb [options] [programfile] [arguments]
[48] Fix | Delete
# -f Suppress read of ~/.irbrc
[49] Fix | Delete
# -d Set $DEBUG to true (same as `ruby -d')
[50] Fix | Delete
# -r load-module Same as `ruby -r'
[51] Fix | Delete
# -I path Specify $LOAD_PATH directory
[52] Fix | Delete
# -U Same as `ruby -U`
[53] Fix | Delete
# -E enc Same as `ruby -E`
[54] Fix | Delete
# -w Same as `ruby -w`
[55] Fix | Delete
# -W[level=2] Same as `ruby -W`
[56] Fix | Delete
# --inspect Use `inspect' for output (default except for bc mode)
[57] Fix | Delete
# --noinspect Don't use inspect for output
[58] Fix | Delete
# --readline Use Readline extension module
[59] Fix | Delete
# --noreadline Don't use Readline extension module
[60] Fix | Delete
# --prompt prompt-mode
[61] Fix | Delete
# --prompt-mode prompt-mode
[62] Fix | Delete
# Switch prompt mode. Pre-defined prompt modes are
[63] Fix | Delete
# `default', `simple', `xmp' and `inf-ruby'
[64] Fix | Delete
# --inf-ruby-mode Use prompt appropriate for inf-ruby-mode on emacs.
[65] Fix | Delete
# Suppresses --readline.
[66] Fix | Delete
# --simple-prompt Simple prompt mode
[67] Fix | Delete
# --noprompt No prompt mode
[68] Fix | Delete
# --tracer Display trace for each execution of commands.
[69] Fix | Delete
# --back-trace-limit n
[70] Fix | Delete
# Display backtrace top n and tail n. The default
[71] Fix | Delete
# value is 16.
[72] Fix | Delete
# --irb_debug n Set internal debug level to n (not for popular use)
[73] Fix | Delete
# -v, --version Print the version of irb
[74] Fix | Delete
#
[75] Fix | Delete
# == Configuration
[76] Fix | Delete
#
[77] Fix | Delete
# IRB reads from <code>~/.irbrc</code> when it's invoked.
[78] Fix | Delete
#
[79] Fix | Delete
# If <code>~/.irbrc</code> doesn't exist, +irb+ will try to read in the following order:
[80] Fix | Delete
#
[81] Fix | Delete
# * +.irbrc+
[82] Fix | Delete
# * +irb.rc+
[83] Fix | Delete
# * +_irbrc+
[84] Fix | Delete
# * <code>$irbrc</code>
[85] Fix | Delete
#
[86] Fix | Delete
# The following are alternatives to the command line options. To use them type
[87] Fix | Delete
# as follows in an +irb+ session:
[88] Fix | Delete
#
[89] Fix | Delete
# IRB.conf[:IRB_NAME]="irb"
[90] Fix | Delete
# IRB.conf[:INSPECT_MODE]=nil
[91] Fix | Delete
# IRB.conf[:IRB_RC] = nil
[92] Fix | Delete
# IRB.conf[:BACK_TRACE_LIMIT]=16
[93] Fix | Delete
# IRB.conf[:USE_LOADER] = false
[94] Fix | Delete
# IRB.conf[:USE_READLINE] = nil
[95] Fix | Delete
# IRB.conf[:USE_TRACER] = false
[96] Fix | Delete
# IRB.conf[:IGNORE_SIGINT] = true
[97] Fix | Delete
# IRB.conf[:IGNORE_EOF] = false
[98] Fix | Delete
# IRB.conf[:PROMPT_MODE] = :DEFAULT
[99] Fix | Delete
# IRB.conf[:PROMPT] = {...}
[100] Fix | Delete
# IRB.conf[:DEBUG_LEVEL]=0
[101] Fix | Delete
#
[102] Fix | Delete
# === Auto indentation
[103] Fix | Delete
#
[104] Fix | Delete
# To enable auto-indent mode in irb, add the following to your +.irbrc+:
[105] Fix | Delete
#
[106] Fix | Delete
# IRB.conf[:AUTO_INDENT] = true
[107] Fix | Delete
#
[108] Fix | Delete
# === Autocompletion
[109] Fix | Delete
#
[110] Fix | Delete
# To enable autocompletion for irb, add the following to your +.irbrc+:
[111] Fix | Delete
#
[112] Fix | Delete
# require 'irb/completion'
[113] Fix | Delete
#
[114] Fix | Delete
# === History
[115] Fix | Delete
#
[116] Fix | Delete
# By default, irb disables history and will not store any commands you used.
[117] Fix | Delete
#
[118] Fix | Delete
# If you want to enable history, add the following to your +.irbrc+:
[119] Fix | Delete
#
[120] Fix | Delete
# IRB.conf[:SAVE_HISTORY] = 1000
[121] Fix | Delete
#
[122] Fix | Delete
# This will now store the last 1000 commands in <code>~/.irb_history</code>.
[123] Fix | Delete
#
[124] Fix | Delete
# See IRB::Context#save_history= for more information.
[125] Fix | Delete
#
[126] Fix | Delete
# == Customizing the IRB Prompt
[127] Fix | Delete
#
[128] Fix | Delete
# In order to customize the prompt, you can change the following Hash:
[129] Fix | Delete
#
[130] Fix | Delete
# IRB.conf[:PROMPT]
[131] Fix | Delete
#
[132] Fix | Delete
# This example can be used in your +.irbrc+
[133] Fix | Delete
#
[134] Fix | Delete
# IRB.conf[:PROMPT][:MY_PROMPT] = { # name of prompt mode
[135] Fix | Delete
# :AUTO_INDENT => true, # enables auto-indent mode
[136] Fix | Delete
# :PROMPT_I => ">> ", # simple prompt
[137] Fix | Delete
# :PROMPT_S => nil, # prompt for continuated strings
[138] Fix | Delete
# :PROMPT_C => nil, # prompt for continuated statement
[139] Fix | Delete
# :RETURN => " ==>%s\n" # format to return value
[140] Fix | Delete
# }
[141] Fix | Delete
#
[142] Fix | Delete
# IRB.conf[:PROMPT_MODE] = :MY_PROMPT
[143] Fix | Delete
#
[144] Fix | Delete
# Or, invoke irb with the above prompt mode by:
[145] Fix | Delete
#
[146] Fix | Delete
# irb --prompt my-prompt
[147] Fix | Delete
#
[148] Fix | Delete
# Constants +PROMPT_I+, +PROMPT_S+ and +PROMPT_C+ specify the format. In the
[149] Fix | Delete
# prompt specification, some special strings are available:
[150] Fix | Delete
#
[151] Fix | Delete
# %N # command name which is running
[152] Fix | Delete
# %m # to_s of main object (self)
[153] Fix | Delete
# %M # inspect of main object (self)
[154] Fix | Delete
# %l # type of string(", ', /, ]), `]' is inner %w[...]
[155] Fix | Delete
# %NNi # indent level. NN is digits and means as same as printf("%NNd").
[156] Fix | Delete
# # It can be omitted
[157] Fix | Delete
# %NNn # line number.
[158] Fix | Delete
# %% # %
[159] Fix | Delete
#
[160] Fix | Delete
# For instance, the default prompt mode is defined as follows:
[161] Fix | Delete
#
[162] Fix | Delete
# IRB.conf[:PROMPT_MODE][:DEFAULT] = {
[163] Fix | Delete
# :PROMPT_I => "%N(%m):%03n:%i> ",
[164] Fix | Delete
# :PROMPT_S => "%N(%m):%03n:%i%l ",
[165] Fix | Delete
# :PROMPT_C => "%N(%m):%03n:%i* ",
[166] Fix | Delete
# :RETURN => "%s\n" # used to printf
[167] Fix | Delete
# }
[168] Fix | Delete
#
[169] Fix | Delete
# irb comes with a number of available modes:
[170] Fix | Delete
#
[171] Fix | Delete
# # :NULL:
[172] Fix | Delete
# # :PROMPT_I:
[173] Fix | Delete
# # :PROMPT_N:
[174] Fix | Delete
# # :PROMPT_S:
[175] Fix | Delete
# # :PROMPT_C:
[176] Fix | Delete
# # :RETURN: |
[177] Fix | Delete
# # %s
[178] Fix | Delete
# # :DEFAULT:
[179] Fix | Delete
# # :PROMPT_I: ! '%N(%m):%03n:%i> '
[180] Fix | Delete
# # :PROMPT_N: ! '%N(%m):%03n:%i> '
[181] Fix | Delete
# # :PROMPT_S: ! '%N(%m):%03n:%i%l '
[182] Fix | Delete
# # :PROMPT_C: ! '%N(%m):%03n:%i* '
[183] Fix | Delete
# # :RETURN: |
[184] Fix | Delete
# # => %s
[185] Fix | Delete
# # :CLASSIC:
[186] Fix | Delete
# # :PROMPT_I: ! '%N(%m):%03n:%i> '
[187] Fix | Delete
# # :PROMPT_N: ! '%N(%m):%03n:%i> '
[188] Fix | Delete
# # :PROMPT_S: ! '%N(%m):%03n:%i%l '
[189] Fix | Delete
# # :PROMPT_C: ! '%N(%m):%03n:%i* '
[190] Fix | Delete
# # :RETURN: |
[191] Fix | Delete
# # %s
[192] Fix | Delete
# # :SIMPLE:
[193] Fix | Delete
# # :PROMPT_I: ! '>> '
[194] Fix | Delete
# # :PROMPT_N: ! '>> '
[195] Fix | Delete
# # :PROMPT_S:
[196] Fix | Delete
# # :PROMPT_C: ! '?> '
[197] Fix | Delete
# # :RETURN: |
[198] Fix | Delete
# # => %s
[199] Fix | Delete
# # :INF_RUBY:
[200] Fix | Delete
# # :PROMPT_I: ! '%N(%m):%03n:%i> '
[201] Fix | Delete
# # :PROMPT_N:
[202] Fix | Delete
# # :PROMPT_S:
[203] Fix | Delete
# # :PROMPT_C:
[204] Fix | Delete
# # :RETURN: |
[205] Fix | Delete
# # %s
[206] Fix | Delete
# # :AUTO_INDENT: true
[207] Fix | Delete
# # :XMP:
[208] Fix | Delete
# # :PROMPT_I:
[209] Fix | Delete
# # :PROMPT_N:
[210] Fix | Delete
# # :PROMPT_S:
[211] Fix | Delete
# # :PROMPT_C:
[212] Fix | Delete
# # :RETURN: |2
[213] Fix | Delete
# # ==>%s
[214] Fix | Delete
#
[215] Fix | Delete
# == Restrictions
[216] Fix | Delete
#
[217] Fix | Delete
# Because irb evaluates input immediately after it is syntactically complete,
[218] Fix | Delete
# the results may be slightly different than directly using Ruby.
[219] Fix | Delete
#
[220] Fix | Delete
# == IRB Sessions
[221] Fix | Delete
#
[222] Fix | Delete
# IRB has a special feature, that allows you to manage many sessions at once.
[223] Fix | Delete
#
[224] Fix | Delete
# You can create new sessions with Irb.irb, and get a list of current sessions
[225] Fix | Delete
# with the +jobs+ command in the prompt.
[226] Fix | Delete
#
[227] Fix | Delete
# === Commands
[228] Fix | Delete
#
[229] Fix | Delete
# JobManager provides commands to handle the current sessions:
[230] Fix | Delete
#
[231] Fix | Delete
# jobs # List of current sessions
[232] Fix | Delete
# fg # Switches to the session of the given number
[233] Fix | Delete
# kill # Kills the session with the given number
[234] Fix | Delete
#
[235] Fix | Delete
# The +exit+ command, or ::irb_exit, will quit the current session and call any
[236] Fix | Delete
# exit hooks with IRB.irb_at_exit.
[237] Fix | Delete
#
[238] Fix | Delete
# A few commands for loading files within the session are also available:
[239] Fix | Delete
#
[240] Fix | Delete
# +source+::
[241] Fix | Delete
# Loads a given file in the current session and displays the source lines,
[242] Fix | Delete
# see IrbLoader#source_file
[243] Fix | Delete
# +irb_load+::
[244] Fix | Delete
# Loads the given file similarly to Kernel#load, see IrbLoader#irb_load
[245] Fix | Delete
# +irb_require+::
[246] Fix | Delete
# Loads the given file similarly to Kernel#require
[247] Fix | Delete
#
[248] Fix | Delete
# === Configuration
[249] Fix | Delete
#
[250] Fix | Delete
# The command line options, or IRB.conf, specify the default behavior of
[251] Fix | Delete
# Irb.irb.
[252] Fix | Delete
#
[253] Fix | Delete
# On the other hand, each conf in IRB@Command+line+options is used to
[254] Fix | Delete
# individually configure IRB.irb.
[255] Fix | Delete
#
[256] Fix | Delete
# If a proc is set for IRB.conf[:IRB_RC], its will be invoked after execution
[257] Fix | Delete
# of that proc with the context of the current session as its argument. Each
[258] Fix | Delete
# session can be configured using this mechanism.
[259] Fix | Delete
#
[260] Fix | Delete
# === Session variables
[261] Fix | Delete
#
[262] Fix | Delete
# There are a few variables in every Irb session that can come in handy:
[263] Fix | Delete
#
[264] Fix | Delete
# <code>_</code>::
[265] Fix | Delete
# The value command executed, as a local variable
[266] Fix | Delete
# <code>__</code>::
[267] Fix | Delete
# The history of evaluated commands
[268] Fix | Delete
# <code>__[line_no]</code>::
[269] Fix | Delete
# Returns the evaluation value at the given line number, +line_no+.
[270] Fix | Delete
# If +line_no+ is a negative, the return value +line_no+ many lines before
[271] Fix | Delete
# the most recent return value.
[272] Fix | Delete
#
[273] Fix | Delete
# === Example using IRB Sessions
[274] Fix | Delete
#
[275] Fix | Delete
# # invoke a new session
[276] Fix | Delete
# irb(main):001:0> irb
[277] Fix | Delete
# # list open sessions
[278] Fix | Delete
# irb.1(main):001:0> jobs
[279] Fix | Delete
# #0->irb on main (#<Thread:0x400fb7e4> : stop)
[280] Fix | Delete
# #1->irb#1 on main (#<Thread:0x40125d64> : running)
[281] Fix | Delete
#
[282] Fix | Delete
# # change the active session
[283] Fix | Delete
# irb.1(main):002:0> fg 0
[284] Fix | Delete
# # define class Foo in top-level session
[285] Fix | Delete
# irb(main):002:0> class Foo;end
[286] Fix | Delete
# # invoke a new session with the context of Foo
[287] Fix | Delete
# irb(main):003:0> irb Foo
[288] Fix | Delete
# # define Foo#foo
[289] Fix | Delete
# irb.2(Foo):001:0> def foo
[290] Fix | Delete
# irb.2(Foo):002:1> print 1
[291] Fix | Delete
# irb.2(Foo):003:1> end
[292] Fix | Delete
#
[293] Fix | Delete
# # change the active session
[294] Fix | Delete
# irb.2(Foo):004:0> fg 0
[295] Fix | Delete
# # list open sessions
[296] Fix | Delete
# irb(main):004:0> jobs
[297] Fix | Delete
# #0->irb on main (#<Thread:0x400fb7e4> : running)
[298] Fix | Delete
# #1->irb#1 on main (#<Thread:0x40125d64> : stop)
[299] Fix | Delete
# #2->irb#2 on Foo (#<Thread:0x4011d54c> : stop)
[300] Fix | Delete
# # check if Foo#foo is available
[301] Fix | Delete
# irb(main):005:0> Foo.instance_methods #=> [:foo, ...]
[302] Fix | Delete
#
[303] Fix | Delete
# # change the active sesssion
[304] Fix | Delete
# irb(main):006:0> fg 2
[305] Fix | Delete
# # define Foo#bar in the context of Foo
[306] Fix | Delete
# irb.2(Foo):005:0> def bar
[307] Fix | Delete
# irb.2(Foo):006:1> print "bar"
[308] Fix | Delete
# irb.2(Foo):007:1> end
[309] Fix | Delete
# irb.2(Foo):010:0> Foo.instance_methods #=> [:bar, :foo, ...]
[310] Fix | Delete
#
[311] Fix | Delete
# # change the active session
[312] Fix | Delete
# irb.2(Foo):011:0> fg 0
[313] Fix | Delete
# irb(main):007:0> f = Foo.new #=> #<Foo:0x4010af3c>
[314] Fix | Delete
# # invoke a new session with the context of f (instance of Foo)
[315] Fix | Delete
# irb(main):008:0> irb f
[316] Fix | Delete
# # list open sessions
[317] Fix | Delete
# irb.3(<Foo:0x4010af3c>):001:0> jobs
[318] Fix | Delete
# #0->irb on main (#<Thread:0x400fb7e4> : stop)
[319] Fix | Delete
# #1->irb#1 on main (#<Thread:0x40125d64> : stop)
[320] Fix | Delete
# #2->irb#2 on Foo (#<Thread:0x4011d54c> : stop)
[321] Fix | Delete
# #3->irb#3 on #<Foo:0x4010af3c> (#<Thread:0x4010a1e0> : running)
[322] Fix | Delete
# # evaluate f.foo
[323] Fix | Delete
# irb.3(<Foo:0x4010af3c>):002:0> foo #=> 1 => nil
[324] Fix | Delete
# # evaluate f.bar
[325] Fix | Delete
# irb.3(<Foo:0x4010af3c>):003:0> bar #=> bar => nil
[326] Fix | Delete
# # kill jobs 1, 2, and 3
[327] Fix | Delete
# irb.3(<Foo:0x4010af3c>):004:0> kill 1, 2, 3
[328] Fix | Delete
# # list open sessions, should only include main session
[329] Fix | Delete
# irb(main):009:0> jobs
[330] Fix | Delete
# #0->irb on main (#<Thread:0x400fb7e4> : running)
[331] Fix | Delete
# # quit irb
[332] Fix | Delete
# irb(main):010:0> exit
[333] Fix | Delete
module IRB
[334] Fix | Delete
[335] Fix | Delete
# An exception raised by IRB.irb_abort
[336] Fix | Delete
class Abort < Exception;end
[337] Fix | Delete
[338] Fix | Delete
@CONF = {}
[339] Fix | Delete
[340] Fix | Delete
[341] Fix | Delete
# Displays current configuration.
[342] Fix | Delete
#
[343] Fix | Delete
# Modifying the configuration is achieved by sending a message to IRB.conf.
[344] Fix | Delete
#
[345] Fix | Delete
# See IRB@Configuration for more information.
[346] Fix | Delete
def IRB.conf
[347] Fix | Delete
@CONF
[348] Fix | Delete
end
[349] Fix | Delete
[350] Fix | Delete
# Returns the current version of IRB, including release version and last
[351] Fix | Delete
# updated date.
[352] Fix | Delete
def IRB.version
[353] Fix | Delete
if v = @CONF[:VERSION] then return v end
[354] Fix | Delete
[355] Fix | Delete
require "irb/version"
[356] Fix | Delete
rv = @RELEASE_VERSION.sub(/\.0/, "")
[357] Fix | Delete
@CONF[:VERSION] = format("irb %s(%s)", rv, @LAST_UPDATE_DATE)
[358] Fix | Delete
end
[359] Fix | Delete
[360] Fix | Delete
# The current IRB::Context of the session, see IRB.conf
[361] Fix | Delete
#
[362] Fix | Delete
# irb
[363] Fix | Delete
# irb(main):001:0> IRB.CurrentContext.irb_name = "foo"
[364] Fix | Delete
# foo(main):002:0> IRB.conf[:MAIN_CONTEXT].irb_name #=> "foo"
[365] Fix | Delete
def IRB.CurrentContext
[366] Fix | Delete
IRB.conf[:MAIN_CONTEXT]
[367] Fix | Delete
end
[368] Fix | Delete
[369] Fix | Delete
# Initializes IRB and creates a new Irb.irb object at the +TOPLEVEL_BINDING+
[370] Fix | Delete
def IRB.start(ap_path = nil)
[371] Fix | Delete
STDOUT.sync = true
[372] Fix | Delete
$0 = File::basename(ap_path, ".rb") if ap_path
[373] Fix | Delete
[374] Fix | Delete
IRB.setup(ap_path)
[375] Fix | Delete
[376] Fix | Delete
if @CONF[:SCRIPT]
[377] Fix | Delete
irb = Irb.new(nil, @CONF[:SCRIPT])
[378] Fix | Delete
else
[379] Fix | Delete
irb = Irb.new
[380] Fix | Delete
end
[381] Fix | Delete
irb.run(@CONF)
[382] Fix | Delete
end
[383] Fix | Delete
[384] Fix | Delete
# Calls each event hook of IRB.conf[:AT_EXIT] when the current session quits.
[385] Fix | Delete
def IRB.irb_at_exit
[386] Fix | Delete
@CONF[:AT_EXIT].each{|hook| hook.call}
[387] Fix | Delete
end
[388] Fix | Delete
[389] Fix | Delete
# Quits irb
[390] Fix | Delete
def IRB.irb_exit(irb, ret)
[391] Fix | Delete
throw :IRB_EXIT, ret
[392] Fix | Delete
end
[393] Fix | Delete
[394] Fix | Delete
# Aborts then interrupts irb.
[395] Fix | Delete
#
[396] Fix | Delete
# Will raise an Abort exception, or the given +exception+.
[397] Fix | Delete
def IRB.irb_abort(irb, exception = Abort)
[398] Fix | Delete
if defined? Thread
[399] Fix | Delete
irb.context.thread.raise exception, "abort then interrupt!"
[400] Fix | Delete
else
[401] Fix | Delete
raise exception, "abort then interrupt!"
[402] Fix | Delete
end
[403] Fix | Delete
end
[404] Fix | Delete
[405] Fix | Delete
class Irb
[406] Fix | Delete
# Creates a new irb session
[407] Fix | Delete
def initialize(workspace = nil, input_method = nil, output_method = nil)
[408] Fix | Delete
@context = Context.new(self, workspace, input_method, output_method)
[409] Fix | Delete
@context.main.extend ExtendCommandBundle
[410] Fix | Delete
@signal_status = :IN_IRB
[411] Fix | Delete
[412] Fix | Delete
@scanner = RubyLex.new
[413] Fix | Delete
@scanner.exception_on_syntax_error = false
[414] Fix | Delete
end
[415] Fix | Delete
[416] Fix | Delete
def run(conf = IRB.conf)
[417] Fix | Delete
conf[:IRB_RC].call(context) if conf[:IRB_RC]
[418] Fix | Delete
conf[:MAIN_CONTEXT] = context
[419] Fix | Delete
[420] Fix | Delete
trap("SIGINT") do
[421] Fix | Delete
signal_handle
[422] Fix | Delete
end
[423] Fix | Delete
[424] Fix | Delete
begin
[425] Fix | Delete
catch(:IRB_EXIT) do
[426] Fix | Delete
eval_input
[427] Fix | Delete
end
[428] Fix | Delete
ensure
[429] Fix | Delete
conf[:AT_EXIT].each{|hook| hook.call}
[430] Fix | Delete
end
[431] Fix | Delete
end
[432] Fix | Delete
[433] Fix | Delete
# Returns the current context of this irb session
[434] Fix | Delete
attr_reader :context
[435] Fix | Delete
# The lexer used by this irb session
[436] Fix | Delete
attr_accessor :scanner
[437] Fix | Delete
[438] Fix | Delete
# Evaluates input for this session.
[439] Fix | Delete
def eval_input
[440] Fix | Delete
@scanner.set_prompt do
[441] Fix | Delete
|ltype, indent, continue, line_no|
[442] Fix | Delete
if ltype
[443] Fix | Delete
f = @context.prompt_s
[444] Fix | Delete
elsif continue
[445] Fix | Delete
f = @context.prompt_c
[446] Fix | Delete
elsif indent > 0
[447] Fix | Delete
f = @context.prompt_n
[448] Fix | Delete
else
[449] Fix | Delete
f = @context.prompt_i
[450] Fix | Delete
end
[451] Fix | Delete
f = "" unless f
[452] Fix | Delete
if @context.prompting?
[453] Fix | Delete
@context.io.prompt = p = prompt(f, ltype, indent, line_no)
[454] Fix | Delete
else
[455] Fix | Delete
@context.io.prompt = p = ""
[456] Fix | Delete
end
[457] Fix | Delete
if @context.auto_indent_mode
[458] Fix | Delete
unless ltype
[459] Fix | Delete
ind = prompt(@context.prompt_i, ltype, indent, line_no)[/.*\z/].size +
[460] Fix | Delete
indent * 2 - p.size
[461] Fix | Delete
ind += 2 if continue
[462] Fix | Delete
@context.io.prompt = p + " " * ind if ind > 0
[463] Fix | Delete
end
[464] Fix | Delete
end
[465] Fix | Delete
end
[466] Fix | Delete
[467] Fix | Delete
@scanner.set_input(@context.io) do
[468] Fix | Delete
signal_status(:IN_INPUT) do
[469] Fix | Delete
if l = @context.io.gets
[470] Fix | Delete
print l if @context.verbose?
[471] Fix | Delete
else
[472] Fix | Delete
if @context.ignore_eof? and @context.io.readable_after_eof?
[473] Fix | Delete
l = "\n"
[474] Fix | Delete
if @context.verbose?
[475] Fix | Delete
printf "Use \"exit\" to leave %s\n", @context.ap_name
[476] Fix | Delete
end
[477] Fix | Delete
else
[478] Fix | Delete
print "\n"
[479] Fix | Delete
end
[480] Fix | Delete
end
[481] Fix | Delete
l
[482] Fix | Delete
end
[483] Fix | Delete
end
[484] Fix | Delete
[485] Fix | Delete
@scanner.each_top_level_statement do |line, line_no|
[486] Fix | Delete
signal_status(:IN_EVAL) do
[487] Fix | Delete
begin
[488] Fix | Delete
line.untaint
[489] Fix | Delete
@context.evaluate(line, line_no)
[490] Fix | Delete
output_value if @context.echo?
[491] Fix | Delete
exc = nil
[492] Fix | Delete
rescue Interrupt => exc
[493] Fix | Delete
rescue SystemExit, SignalException
[494] Fix | Delete
raise
[495] Fix | Delete
rescue Exception => exc
[496] Fix | Delete
end
[497] Fix | Delete
if exc
[498] Fix | Delete
if exc.backtrace && exc.backtrace[0] =~ /irb(2)?(\/.*|-.*|\.rb)?:/ && exc.class.to_s !~ /^IRB/ &&
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function