1 .TH IRB "1" "December 2002"
3 irb \- interactive ruby
9 irb stands for `interactive ruby'. irb is a tool to execute interactively
10 ruby expressions read from stdin.
11 Use of irb is easy if you know ruby. Executing irb, prompts are
12 displayed as follows. Then, enter expression of ruby. A input is
13 executed when it is syntacticaly completed.
17 \& irb(main):001:0> 1+2
19 \& irb(main):002:0> class Foo
20 \& irb(main):003:1> def foo
21 \& irb(main):004:2> print 1
22 \& irb(main):005:2> end
23 \& irb(main):006:1> end
28 And, Readline extesion module can be used with irb. Using Readline
29 is the standard default action if Readline is installed.
38 suppress read ~/.irbrc
43 bc mode (fraction or matrix are available)
48 set $DEBUG to true (same as `ruby \-d')
58 uses `inspect' for output (the default except bc mode)
63 doesn't uses inspect for output
68 uses Readline extension module
73 doesn't use Readline extension module
77 \-\-prompt prompt\-mode
81 \-\-prompt\-mode prompt\-mode
82 switches prompt mode. Pre\-defined prompt modes are
83 `default', `simple', `xmp' and `inf\-ruby'
88 uses prompt appreciate for inf\-ruby\-mode on emacs.
89 Suppresses \-\-readline.
104 display trace for each execution of commands.
108 \-\-back\-trace\-limit n
109 displayes backtrace top n and tail n. The default
115 sets internal debug level to n (It shouldn't be used)
120 prints the version of irb
124 irb reads `~/.irbrc' when it is invoked. If `~/.irbrb' doesn't exist
125 irb try to read in the order `.irbrc', `irb.rc', `_irbrc' then `$irbrc'.
126 The following is altanative to the command line option. To use them
127 type as follows in an irb session.
130 \& IRB.conf[:IRB_NAME]="irb"
131 \& IRB.conf[:MATH_MODE]=false
132 \& IRB.conf[:USE_TRACER]=false
133 \& IRB.conf[:USE_LOADER]=false
134 \& IRB.conf[:IGNORE_SIGINT]=true
135 \& IRB.conf[:IGNORE_EOF]=false
136 \& IRB.conf[:INSPECT_MODE]=nil
137 \& IRB.conf[:IRB_RC] = nil
138 \& IRB.conf[:BACK_TRACE_LIMIT]=16
139 \& IRB.conf[:USE_LOADER] = false
140 \& IRB.conf[:USE_READLINE] = nil
141 \& IRB.conf[:USE_TRACER] = false
142 \& IRB.conf[:IGNORE_SIGINT] = true
143 \& IRB.conf[:IGNORE_EOF] = false
144 \& IRB.conf[:PROMPT_MODE] = :DEFALUT
145 \& IRB.conf[:PROMPT] = {...}
146 \& IRB.conf[:DEBUG_LEVEL]=0
147 \& IRB.conf[:VERBOSE]=true
149 .SH Customizing prompt
152 To costomize the prompt you set a variable
158 For example, describe as follows in `.irbrc'.
161 \& IRB.conf[:PROMPT][:MY_PROMPT] = { # name of prompt mode
162 \& :PROMPT_I => nil, # normal prompt
163 \& :PROMPT_S => nil, # prompt for continuated strings
164 \& :PROMPT_C => nil, # prompt for continuated statement
165 \& :RETURN => " ==>%s\\n" # format to return value
169 Then, invoke irb with the above prompt mode by
172 \& $ irb1.8 \-\-prompt my\-prompt
175 Or add the following in `.irbrc'.
178 \& IRB.conf[:PROMPT_MODE] = :MY_PROMPT
181 Constants PROMPT_I, PROMPT_S and PROMPT_C specifies the format.
182 In the prompt specification, some special strings are available.
185 \& %N command name which is running
186 \& %m to_s of main object (self)
187 \& %M inspect of main object (self)
188 \& %l type of string(", ', /, ]), `]' is inner %w[...]
189 \& %NNi indent level. NN is degits and means as same as printf("%NNd").
194 For instance, the default prompt mode is defined as follows:
195 IRB.conf[:PROMPT_MODE][:DEFAULT] = {
199 PROMPT_I => "%N(%m):%03n:%i> ",
203 PROMPT_S => "%N(%m):%03n:%i%l ",
207 PROMPT_C => "%N(%m):%03n:%i* ",
212 RETURN is used to printf.
213 .SH Configurating subirb
216 The command line option or IRB.conf specify the default behavior of
217 (sub)irb. On the other hand, each conf of in the next sction `6. Command'
218 is used to individually configurate (sub)irb.
219 If proc is set to IRB.conf[:IRB_RC], its subirb will be invoked after
220 execution of that proc under giving the context of irb as its
221 aregument. By this mechanism each subirb can be configurated.
225 For irb commands, both simple name and `irb_'\-prefixed name are prepared.
231 if you've done cb (see below), exit from the binding mode.
237 Displays current configuration. Modifing the configuration is
238 achieved by sending message to `conf'.
242 conf.back_trace_limit
243 Sets display lines of backtrace as top n and tail n.
244 The default value is 16.
249 Sets debug level of irb.
253 conf.ignore_eof = true/false
254 Whether ^D (control\-d) will be ignored or not.
255 If false is set, ^D means quit.
259 conf.ignore_sigint= true/false
260 Whether ^C (control\-c) will be ignored or not.
261 If false is set, ^D means quit. If true,
263 \& during input: cancel inputing then return to top level.
264 \& during execute: abondon current execution.
269 conf.inf_ruby_mode = true/false
270 Whether inf\-ruby\-mode or not. The default value is false.
274 conf.inspect_mode = true/false/nil
275 Specifies inspect mode.
276 true: display inspect
278 nil: inspect mode in non math mode,
280 \& non inspect mode in math mode.
291 Whether bc mode or not.
295 conf.use_loader = true/false
296 Whether irb's own file reader method is used when load/require or not.
297 This mode is globaly affected (irb wide).
302 prompt for a continuating statement (e.g, immediately after of `if')
312 prompt for a continuating string
317 Whether ~/.irbrc is read or not.
321 conf.use_prompt = true/false
326 conf.use_readline = true/false/nil
327 Whether readline is used or not.
330 nil: intends to use readline except for inf\-reuby\-mode (default)
335 Whether verbose messages are display or not.
339 cb, irb_change_binding [obj]
340 Enter new binding which has a distinct scope of local variables.
341 If obj is given, obj will be self.
346 Invoke subirb. If obj is given, obj will be self.
356 Switch into specified subirb. The following is candidates of n:
361 \& self(obj which is specified of irb obj)
367 Kill subirb. The means of n is as same as the case of irb_fg.
376 The latest value of evaluation (it is local)
382 \& irb(main):001:0> irb # invoke subirb
383 \& irb#1(main):001:0> jobs # list of subirbs
384 \& #0\->irb on main (#<Thread:0x400fb7e4> : stop)
385 \& #1\->irb#1 on main (#<Thread:0x40125d64> : running)
387 \& irb#1(main):002:0> fg 0 # switch job
389 \& irb(main):002:0> class Foo;end
391 \& irb(main):003:0> irb Foo # invoke subirb which has the
397 \& irb#2(Foo):001:0> def foo # define Foo#foo
398 \& irb#2(Foo):002:1> print 1
399 \& irb#2(Foo):003:1> end
401 \& irb#2(Foo):004:0> fg 0 # switch job
403 \& irb(main):004:0> jobs # list of job
404 \& #0\->irb on main (#<Thread:0x400fb7e4> : running)
405 \& #1\->irb#1 on main (#<Thread:0x40125d64> : stop)
406 \& #2\->irb#2 on Foo (#<Thread:0x4011d54c> : stop)
408 \& irb(main):005:0> Foo.instance_methods # Foo#foo is defined asurely
410 \& irb(main):006:0> fg 2 # switch job
412 \& irb#2(Foo):005:0> def bar # define Foo#bar
413 \& irb#2(Foo):006:1> print "bar"
414 \& irb#2(Foo):007:1> end
416 \& irb#2(Foo):010:0> Foo.instance_methods
418 \& irb#2(Foo):011:0> fg 0
420 \& irb(main):007:0> f = Foo.new
422 \& irb(main):008:0> irb f # invoke subirb which has the
425 \& # context of f (instance of Foo)
428 \& irb#3(#<Foo:0x4010af3c>):001:0> jobs
429 \& #0\->irb on main (#<Thread:0x400fb7e4> : stop)
430 \& #1\->irb#1 on main (#<Thread:0x40125d64> : stop)
431 \& #2\->irb#2 on Foo (#<Thread:0x4011d54c> : stop)
432 \& #3\->irb#3 on #<Foo:0x4010af3c> (#<Thread:0x4010a1e0> : running)
434 \& irb#3(#<Foo:0x4010af3c>):002:0> foo # evaluate f.foo
436 \& irb#3(#<Foo:0x4010af3c>):003:0> bar # evaluate f.bar
438 \& irb#3(#<Foo:0x4010af3c>):004:0> kill 1, 2, 3# kill job
440 \& irb(main):009:0> jobs
441 \& #0\->irb on main (#<Thread:0x400fb7e4> : running)
443 \& irb(main):010:0> exit # exit
448 Because irb evaluates the inputs immediately after the imput is
449 syntactically completed, irb gives slight different result than
450 directly use ruby. Known difference is pointed out here.
451 .SH Declaration of the local variable
454 The following causes an error in ruby:
460 \& \-:2: undefined local variable or method `foo' for #<Object:0x40283118> (NameError)
465 Though, the above will successfully done by irb.
476 Ruby evaluates a code after reading entire of code and determination
477 of the scope of local variables. On the other hand, irb do
478 immediately. More precisely, irb evaluate at first
484 then foo is defined on this timing. It is because of this
486 If you'd like to detect those differences, begin...end can be used:
493 \& NameError: undefined local variable or method `foo' for #<Object:0x4013d0f0>
495 \& (irb_local_binding):1:in `eval'
500 Implementation of Here\-document is incomplete.
504 Irb can not always recognize a symbol as to be Symbol. Concretely, an
505 expression have completed, however Irb regard it as continuation line.