Repository URL to install this package:
|
Version:
2.2.2-1 ▾
|
U:RDoc::NormalModule[iI"IRB:EF@0o:RDoc::Markup::Document:@parts[o;;[lo:RDoc::Markup::Paragraph;[I"SIRB stands for "interactive Ruby" and is a tool to interactively execute Ruby ;TI".expressions read from the standard input.;To:RDoc::Markup::BlankLine o; ;[I"BThe +irb+ command from your shell will start the interpreter.;T@S:RDoc::Markup::Heading:
leveli: textI"
Usage;T@o; ;[I")Use of irb is easy if you know Ruby.;T@o; ;[I"PWhen executing irb, prompts are displayed as follows. Then, enter the Ruby ;TI"Hexpression. An input is executed when it is syntactically complete.;T@o:RDoc::Markup::Verbatim;[I"$ irb
;TI"irb(main):001:0> 1+2
;TI"#=> 3
;TI" irb(main):002:0> class Foo
;TI"irb(main):003:1> def foo
;TI"!irb(main):004:2> print 1
;TI"irb(main):005:2> end
;TI"irb(main):006:1> end
;TI"
#=> nil
;T:@format0o; ;[I"LThe Readline extension module can be used with irb. Use of Readline is ;TI"default if it's installed.;T@S;;i;
I"Command line options;T@o;;[!I"8Usage: irb.rb [options] [programfile] [arguments]
;TI"3 -f Suppress read of ~/.irbrc
;TI"P -m Bc mode (load mathn, fraction or matrix are available)
;TI"@ -d Set $DEBUG to true (same as `ruby -d')
;TI"+ -r load-module Same as `ruby -r'
;TI"6 -I path Specify $LOAD_PATH directory
;TI"+ -U Same as `ruby -U`
;TI"+ -E enc Same as `ruby -E`
;TI"+ -w Same as `ruby -w`
;TI"+ -W[level=2] Same as `ruby -W`
;TI"O --inspect Use `inspect' for output (default except for bc mode)
;TI"6 --noinspect Don't use inspect for output
;TI"7 --readline Use Readline extension module
;TI"= --noreadline Don't use Readline extension module
;TI" --prompt prompt-mode
;TI"! --prompt-mode prompt-mode
;TI"J Switch prompt mode. Pre-defined prompt modes are
;TI"C `default', `simple', `xmp' and `inf-ruby'
;TI"L --inf-ruby-mode Use prompt appropriate for inf-ruby-mode on emacs.
;TI"0 Suppresses --readline.
;TI", --simple-prompt Simple prompt mode
;TI"( --noprompt No prompt mode
;TI"G --tracer Display trace for each execution of commands.
;TI" --back-trace-limit n
;TI"I Display backtrace top n and tail n. The default
;TI"& value is 16.
;TI"M --irb_debug n Set internal debug level to n (not for popular use)
;TI"2 -v, --version Print the version of irb
;T;0S;;i;
I"Configuration;T@o; ;[I"<IRB reads from <code>~/.irbrc</code> when it's invoked.;T@o; ;[I"[If <code>~/.irbrc</code> doesn't exist, +irb+ will try to read in the following order:;T@o:RDoc::Markup::List:
@type:BULLET:@items[ o:RDoc::Markup::ListItem:@label0;[o; ;[I"
+.irbrc+;To;;0;[o; ;[I"
+irb.rc+;To;;0;[o; ;[I"
+_irbrc+;To;;0;[o; ;[I"<code>$irbrc</code>;T@o; ;[I"RThe following are alternatives to the command line options. To use them type ;TI"$as follows in an +irb+ session:;T@o;;[I"IRB.conf[:IRB_NAME]="irb"
;TI" IRB.conf[:MATH_MODE]=false
;TI"!IRB.conf[:INSPECT_MODE]=nil
;TI"IRB.conf[:IRB_RC] = nil
;TI"$IRB.conf[:BACK_TRACE_LIMIT]=16
;TI"#IRB.conf[:USE_LOADER] = false
;TI"#IRB.conf[:USE_READLINE] = nil
;TI"#IRB.conf[:USE_TRACER] = false
;TI"%IRB.conf[:IGNORE_SIGINT] = true
;TI"#IRB.conf[:IGNORE_EOF] = false
;TI"'IRB.conf[:PROMPT_MODE] = :DEFAULT
;TI"IRB.conf[:PROMPT] = {...}
;TI"IRB.conf[:DEBUG_LEVEL]=0
;T;0S;;i;
I"Auto indentation;T@o; ;[I"KTo enable auto-indent mode in irb, add the following to your +.irbrc+:;T@o;;[I"#IRB.conf[:AUTO_INDENT] = true
;T;0S;;i;
I"Autocompletion;T@o; ;[I"JTo enable autocompletion for irb, add the following to your +.irbrc+:;T@o;;[I"require 'irb/completion'
;T;0S;;i;
I"History;T@o; ;[I"OBy default, irb disables history and will not store any commands you used.;T@o; ;[I"GIf you want to enable history, add the following to your +.irbrc+:;T@o;;[I"$IRB.conf[:SAVE_HISTORY] = 1000
;T;0o; ;[I"OThis will now store the last 1000 commands in <code>~/.irb_history</code>.;T@o; ;[I"9See IRB::Context#save_history= for more information.;T@S;;i;
I"Customizing the IRB Prompt;T@o; ;[I"IIn order to customize the prompt, you can change the following Hash:;T@o;;[I"IRB.conf[:PROMPT]
;T;0o; ;[I".This example can be used in your +.irbrc+;T@o;;[I"=IRB.conf[:PROMPT][:MY_PROMPT] = { # name of prompt mode
;TI"B :AUTO_INDENT => true, # enables auto-indent mode
;TI"7 :PROMPT_I => ">> ", # simple prompt
;TI"H :PROMPT_S => nil, # prompt for continuated strings
;TI"J :PROMPT_C => nil, # prompt for continuated statement
;TI"@ :RETURN => " ==>%s\n" # format to return value
;TI"}
;TI"
;TI")IRB.conf[:PROMPT_MODE] = :MY_PROMPT
;T;0o; ;[I"2Or, invoke irb with the above prompt mode by:;T@o;;[I"irb --prompt my-prompt
;T;0o; ;[I"PConstants +PROMPT_I+, +PROMPT_S+ and +PROMPT_C+ specify the format. In the ;TI">prompt specification, some special strings are available:;T@o;;[
I"+%N # command name which is running
;TI"(%m # to_s of main object (self)
;TI"+%M # inspect of main object (self)
;TI">%l # type of string(", ', /, ]), `]' is inner %w[...]
;TI"M%NNi # indent level. NN is digits and means as same as printf("%NNd").
;TI" # It can be ommited
;TI"%NNn # line number.
;TI"%% # %
;T;0o; ;[I"AFor instance, the default prompt mode is defined as follows:;T@o;;[I"*IRB.conf[:PROMPT_MODE][:DEFAULT] = {
;TI"( :PROMPT_I => "%N(%m):%03n:%i> ",
;TI") :PROMPT_S => "%N(%m):%03n:%i%l ",
;TI"( :PROMPT_C => "%N(%m):%03n:%i* ",
;TI"* :RETURN => "%s\n" # used to printf
;TI"}
;T;0o; ;[I"0irb comes with a number of available modes:;T@o;;[0I"# :NULL:
;TI"# :PROMPT_I:
;TI"# :PROMPT_N:
;TI"# :PROMPT_S:
;TI"# :PROMPT_C:
;TI"# :RETURN: |
;TI"# %s
;TI"# :DEFAULT:
;TI")# :PROMPT_I: ! '%N(%m):%03n:%i> '
;TI")# :PROMPT_N: ! '%N(%m):%03n:%i> '
;TI"*# :PROMPT_S: ! '%N(%m):%03n:%i%l '
;TI")# :PROMPT_C: ! '%N(%m):%03n:%i* '
;TI"# :RETURN: |
;TI"# => %s
;TI"# :CLASSIC:
;TI")# :PROMPT_I: ! '%N(%m):%03n:%i> '
;TI")# :PROMPT_N: ! '%N(%m):%03n:%i> '
;TI"*# :PROMPT_S: ! '%N(%m):%03n:%i%l '
;TI")# :PROMPT_C: ! '%N(%m):%03n:%i* '
;TI"# :RETURN: |
;TI"# %s
;TI"# :SIMPLE:
;TI"# :PROMPT_I: ! '>> '
;TI"# :PROMPT_N: ! '>> '
;TI"# :PROMPT_S:
;TI"# :PROMPT_C: ! '?> '
;TI"# :RETURN: |
;TI"# => %s
;TI"# :INF_RUBY:
;TI")# :PROMPT_I: ! '%N(%m):%03n:%i> '
;TI"# :PROMPT_N:
;TI"# :PROMPT_S:
;TI"# :PROMPT_C:
;TI"# :RETURN: |
;TI"# %s
;TI"# :AUTO_INDENT: true
;TI"
# :XMP:
;TI"# :PROMPT_I:
;TI"# :PROMPT_N:
;TI"# :PROMPT_S:
;TI"# :PROMPT_C:
;TI"# :RETURN: |2
;TI"# ==>%s
;T;0S;;i;
I"Restrictions;T@o; ;[I"QBecause irb evaluates input immediately after it is syntactically complete, ;TI"Dthe results may be slightly different than directly using Ruby.;T@S;;i;
I"IRB Sessions;T@o; ;[I"PIRB has a special feature, that allows you to manage many sessions at once.;T@o; ;[I"RYou can create new sessions with Irb.irb, and get a list of current sessions ;TI"+with the +jobs+ command in the prompt.;T@S;;i;
I"
Commands;T@o; ;[I"AJobManager provides commands to handle the current sessions:;T@o;;[I"(jobs # List of current sessions
;TI";fg # Switches to the session of the given number
;TI"7kill # Kills the session with the given number
;T;0o; ;[I"SThe +exit+ command, or ::irb_exit, will quit the current session and call any ;TI"%exit hooks with IRB.irb_at_exit.;T@o; ;[I"LA few commands for loading files within the session are also available:;T@o;;: NOTE;[o;;[I"
+source+;T;[o; ;[I"NLoads a given file in the current session and displays the source lines, ;TI"see IrbLoader#source_file;To;;[I"+irb_load+;T;[o; ;[I"JLoads the given file similarly to Kernel#load, see IrbLoader#irb_load;To;;[I"+irb_require+;T;[o; ;[I"5Loads the given file similarly to Kernel#require;T@S;;i;
I"Configuration;T@o; ;[I"LThe command line options, or IRB.conf, specify the default behavior of ;TI"
Irb.irb.;T@o; ;[I"IOn the other hand, each conf in IRB@Command+line+options is used to ;TI"$individually configure IRB.irb.;T@o; ;[I"QIf a proc is set for IRB.conf[:IRB_RC], its will be invoked after execution ;TI"Pof that proc with the context of the current session as its argument. Each ;TI"4session can be configured using this mechanism.;T@S;;i;
I"Session variables;T@o; ;[I"KThere are a few variables in every Irb session that can come in handy:;T@o;;;;[o;;[I"<code>_</code>;T;[o; ;[I"4The value command executed, as a local variable;To;;[I"<code>__</code>;T;[o; ;[I"&The history of evaluated commands;To;;[I"<code>__[line_no]</code>;T;[o; ;[I"GReturns the evaluation value at the given line number, +line_no+. ;TI"NIf +line_no+ is a negative, the return value +line_no+ many lines before ;TI""the most recent return value.;T@S;;i;
I"Example using IRB Sessions;T@o;;[?I"# invoke a new session
;TI"irb(main):001:0> irb
;TI"# list open sessions
;TI"irb.1(main):001:0> jobs
;TI"5 #0->irb on main (#<Thread:0x400fb7e4> : stop)
;TI": #1->irb#1 on main (#<Thread:0x40125d64> : running)
;TI"
;TI"!# change the active session
;TI"irb.1(main):002:0> fg 0
;TI"-# define class Foo in top-level session
;TI"$irb(main):002:0> class Foo;end
;TI"4# invoke a new session with the context of Foo
;TI"irb(main):003:0> irb Foo
;TI"# define Foo#foo
;TI"irb.2(Foo):001:0> def foo
;TI"!irb.2(Foo):002:1> print 1
;TI"irb.2(Foo):003:1> end
;TI"
;TI"!# change the active session
;TI"irb.2(Foo):004:0> fg 0
;TI"# list open sessions
;TI"irb(main):004:0> jobs
;TI"8 #0->irb on main (#<Thread:0x400fb7e4> : running)
;TI"7 #1->irb#1 on main (#<Thread:0x40125d64> : stop)
;TI"6 #2->irb#2 on Foo (#<Thread:0x4011d54c> : stop)
;TI"%# check if Foo#foo is available
;TI";irb(main):005:0> Foo.instance_methods #=> [:foo, ...]
;TI"
;TI""# change the active sesssion
;TI"irb(main):006:0> fg 2
;TI",# define Foo#bar in the context of Foo
;TI"irb.2(Foo):005:0> def bar
;TI"$irb.2(Foo):006:1> print "bar"
;TI"irb.2(Foo):007:1> end
;TI"Cirb.2(Foo):010:0> Foo.instance_methods #=> [:bar, :foo, ...]
;TI"
;TI"!# change the active session
;TI"irb.2(Foo):011:0> fg 0
;TI"9irb(main):007:0> f = Foo.new #=> #<Foo:0x4010af3c>
;TI"D# invoke a new session with the context of f (instance of Foo)
;TI"irb(main):008:0> irb f
;TI"# list open sessions
;TI")irb.3(<Foo:0x4010af3c>):001:0> jobs
;TI"5 #0->irb on main (#<Thread:0x400fb7e4> : stop)
;TI"7 #1->irb#1 on main (#<Thread:0x40125d64> : stop)
;TI"6 #2->irb#2 on Foo (#<Thread:0x4011d54c> : stop)
;TI"G #3->irb#3 on #<Foo:0x4010af3c> (#<Thread:0x4010a1e0> : running)
;TI"# evaluate f.foo
;TI"5irb.3(<Foo:0x4010af3c>):002:0> foo #=> 1 => nil
;TI"# evaluate f.bar
;TI"7irb.3(<Foo:0x4010af3c>):003:0> bar #=> bar => nil
;TI"# kill jobs 1, 2, and 3
;TI"1irb.3(<Foo:0x4010af3c>):004:0> kill 1, 2, 3
;TI"=# list open sesssions, should only include main session
;TI"irb(main):009:0> jobs
;TI"8 #0->irb on main (#<Thread:0x400fb7e4> : running)
;TI"# quit irb
;TI"irb(main):010:0> exit;T;0:
@fileI"lib/irb.rb;T:0@omit_headings_from_table_of_contents_below0o;;[ ;I"lib/irb/completion.rb;T;0o;;[ ;I"lib/irb/context.rb;T;0o;;[ ;I"lib/irb/ext/math-mode.rb;T;0o;;[ ;I"lib/irb/ext/multi-irb.rb;T;0o;;[ ;I" lib/irb/ext/save-history.rb;T;0o;;[ ;I"lib/irb/ext/tracer.rb;T;0o;;[ ;I"lib/irb/ext/use-loader.rb;T;0o;;[ ;I"lib/irb/frame.rb;T;0o;;[ ;I"lib/irb/help.rb;T;0o;;[ ;I"lib/irb/input-method.rb;T;0o;;[ ;I"lib/irb/magic-file.rb;T;0o;;[ ;I"lib/irb/notifier.rb;T;0o;;[ ;I"lib/irb/output-method.rb;T;0;0;0[ [ [ [[I"
class;T[[:public[[I"CurrentContext;FI"lib/irb.rb;T[I"JobManager;FI"lib/irb/ext/multi-irb.rb;T[I" conf;F@Ô[I"initialize_tracer;FI"lib/irb/ext/tracer.rb;T[I"irb;F@×[I"irb_abort;F@Ô[I"irb_at_exit;F@Ô[I"
irb_exit;F@Ô[I"print_usage;FI"lib/irb/help.rb;T[I"
start;F@Ô[I"version;F@Ô[:protected[ [:private[ [I"
instance;T[[;[ [;[ [;[ [ [U:RDoc::Context::Section[i 0o;;[ ;0;0[,@¡I"lib/irb/cmd/chws.rb;TI"lib/irb/cmd/fork.rb;TI"lib/irb/cmd/help.rb;TI"lib/irb/cmd/load.rb;TI"lib/irb/cmd/nop.rb;TI"lib/irb/cmd/pushws.rb;TI"lib/irb/cmd/subirb.rb;T@¤@§I"lib/irb/ext/change-ws.rb;TI"lib/irb/ext/history.rb;TI"lib/irb/ext/loader.rb;T@ª@@°@³@¶I"lib/irb/ext/workspaces.rb;TI"lib/irb/extend-command.rb;T@¹@¼I"lib/irb/init.rb;T@¿I"lib/irb/inspector.rb;TI"lib/irb/lc/error.rb;TI"&lib/irb/lc/ja/encoding_aliases.rb;TI"lib/irb/lc/ja/error.rb;TI"lib/irb/locale.rb;T@Â@Å@ÈI"lib/irb/ruby-lex.rb;TI"lib/irb/slex.rb;TI"lib/irb/version.rb;TI"lib/irb/workspace.rb;TI"lib/irb/ws-for-case-2.rb;TI"lib/irb/xmp.rb;TI"lib/rdoc/ruby_lex.rb;T@cRDoc::TopLevel