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