]> git.pld-linux.org Git - packages/ruby.git/blame - irb.1
- drop macros.ruby (not needed (rpm-build-macros provides it) and done wrong (not...
[packages/ruby.git] / irb.1
CommitLineData
92275170 1.TH IRB "1" "December 2002"
2.SH NAME
3irb \- interactive ruby
4.SH SYNOPSIS
5.B irb
6[\fIoptions\fR]
7.SH DESCRIPTION
8dd08261 8.PP
9irb stands for `interactive ruby'. irb is a tool to execute interactively
10ruby expressions read from stdin.
8dd08261 11Use of irb is easy if you know ruby. Executing irb, prompts are
12displayed as follows. Then, enter expression of ruby. A input is
13executed when it is syntacticaly completed.
92275170 14
8dd08261 15.nf
92275170 16\& $ irb1.8
8dd08261 17\& irb(main):001:0> 1+2
18\& 3
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
24\& nil
25\& irb(main):007:0>
26.fi
92275170 27
8dd08261 28And, Readline extesion module can be used with irb. Using Readline
29is the standard default action if Readline is installed.
92275170 30.SH OPTIONS
31
8dd08261 32.PP
92275170 33
34.TP
8dd08261 35.fi
92275170 36.B
37\-f
38suppress read ~/.irbrc
39.TP
8dd08261 40.fi
92275170 41.B
42\-m
43bc mode (fraction or matrix are available)
44.TP
8dd08261 45.fi
92275170 46.B
47\-d
48set $DEBUG to true (same as `ruby \-d')
49.TP
8dd08261 50.fi
92275170 51.B
52\-r load\-module
53same as `ruby \-r'
54.TP
8dd08261 55.fi
92275170 56.B
57\-\-inspect
58uses `inspect' for output (the default except bc mode)
59.TP
8dd08261 60.fi
92275170 61.B
62\-\-noinspect
63doesn't uses inspect for output
64.TP
65.fi
66.B
67\-\-readline
68uses Readline extension module
69.TP
8dd08261 70.fi
92275170 71.B
72\-\-noreadline
73doesn't use Readline extension module
74.TP
75.fi
76.B
77\-\-prompt prompt\-mode
78.TP
79.fi
80.B
81\-\-prompt\-mode prompt\-mode
82switches prompt mode. Pre\-defined prompt modes are
83`default', `simple', `xmp' and `inf\-ruby'
84.TP
85.fi
86.B
87\-\-inf\-ruby\-mode
88uses prompt appreciate for inf\-ruby\-mode on emacs.
89Suppresses \-\-readline.
90.TP
91.fi
92.B
93\-\-simple\-prompt
94simple prompt mode
95.TP
96.fi
97.B
98\-\-noprompt
99no prompt
100.TP
101.fi
102.B
103\-\-tracer
104display trace for each execution of commands.
105.TP
106.fi
107.B
108\-\-back\-trace\-limit n
109displayes backtrace top n and tail n. The default
110value is 16.
111.TP
112.fi
113.B
114\-\-irb_debug n
115sets internal debug level to n (It shouldn't be used)
116.TP
117.fi
118.B
119\-v, \-\-version
120prints the version of irb
121.SH CONFIGURATIONS
122
8dd08261 123.PP
124irb reads `~/.irbrc' when it is invoked. If `~/.irbrb' doesn't exist
125irb try to read in the order `.irbrc', `irb.rc', `_irbrc' then `$irbrc'.
126The following is altanative to the command line option. To use them
127type as follows in an irb session.
92275170 128
8dd08261 129.nf
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
148.fi
149.SH Customizing prompt
92275170 150
8dd08261 151.PP
152To costomize the prompt you set a variable
92275170 153
8dd08261 154.nf
155\& IRB.conf[:PROMPT]
156.fi
92275170 157
8dd08261 158For example, describe as follows in `.irbrc'.
92275170 159
8dd08261 160.nf
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
166\& }
167.fi
92275170 168
8dd08261 169Then, invoke irb with the above prompt mode by
92275170 170
8dd08261 171.nf
92275170 172\& $ irb1.8 \-\-prompt my\-prompt
8dd08261 173.fi
92275170 174
8dd08261 175Or add the following in `.irbrc'.
92275170 176
8dd08261 177.nf
178\& IRB.conf[:PROMPT_MODE] = :MY_PROMPT
179.fi
92275170 180
8dd08261 181Constants PROMPT_I, PROMPT_S and PROMPT_C specifies the format.
182In the prompt specification, some special strings are available.
92275170 183
8dd08261 184.nf
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").
190\& It can be ommited
191\& %NNn line number.
192\& %% %
193.fi
194For instance, the default prompt mode is defined as follows:
195IRB.conf[:PROMPT_MODE][:DEFAULT] = {
8dd08261 196.TP
197.fi
198.B
199PROMPT_I => "%N(%m):%03n:%i> ",
8dd08261 200.TP
201.fi
202.B
203PROMPT_S => "%N(%m):%03n:%i%l ",
8dd08261 204.TP
205.fi
206.B
207PROMPT_C => "%N(%m):%03n:%i* ",
8dd08261 208.TP
209.fi
210.B
92275170 211RETURN => "%s\\n"}
8dd08261 212RETURN is used to printf.
213.SH Configurating subirb
92275170 214
8dd08261 215.PP
216The 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'
218is used to individually configurate (sub)irb.
219If proc is set to IRB.conf[:IRB_RC], its subirb will be invoked after
220execution of that proc under giving the context of irb as its
221aregument. By this mechanism each subirb can be configurated.
222.SH Command
92275170 223
8dd08261 224.PP
225For irb commands, both simple name and `irb_'\-prefixed name are prepared.
8dd08261 226.TP
227.fi
228.B
229exit, quit, irb_exit
230Quits (sub)irb.
231if you've done cb (see below), exit from the binding mode.
232
8dd08261 233.TP
234.fi
235.B
236conf, irb_context
237Displays current configuration. Modifing the configuration is
238achieved by sending message to `conf'.
8dd08261 239.TP
240.fi
241.B
242conf.back_trace_limit
243Sets display lines of backtrace as top n and tail n.
244The default value is 16.
8dd08261 245.TP
246.fi
247.B
248conf.debug_level = N
249Sets debug level of irb.
8dd08261 250.TP
251.fi
252.B
253conf.ignore_eof = true/false
254Whether ^D (control\-d) will be ignored or not.
255If false is set, ^D means quit.
8dd08261 256.TP
257.fi
258.B
259conf.ignore_sigint= true/false
260Whether ^C (control\-c) will be ignored or not.
261If false is set, ^D means quit. If true,
8dd08261 262.nf
263\& during input: cancel inputing then return to top level.
264\& during execute: abondon current execution.
265.fi
8dd08261 266.TP
267.fi
268.B
269conf.inf_ruby_mode = true/false
270Whether inf\-ruby\-mode or not. The default value is false.
8dd08261 271.TP
272.fi
273.B
274conf.inspect_mode = true/false/nil
275Specifies inspect mode.
276true: display inspect
277false: display to_s
278nil: inspect mode in non math mode,
8dd08261 279.nf
280\& non inspect mode in math mode.
281.fi
8dd08261 282.TP
283.fi
284.B
285conf.irb_level
286The level of cb.
8dd08261 287.TP
288.fi
289.B
290conf.math_mode
291Whether bc mode or not.
8dd08261 292.TP
293.fi
294.B
295conf.use_loader = true/false
296Whether irb's own file reader method is used when load/require or not.
297This mode is globaly affected (irb wide).
8dd08261 298.TP
299.fi
300.B
301conf.prompt_c
302prompt for a continuating statement (e.g, immediately after of `if')
8dd08261 303.TP
304.fi
305.B
306conf.prompt_i
307standard prompt
8dd08261 308.TP
309.fi
310.B
311conf.prompt_s
312prompt for a continuating string
8dd08261 313.TP
314.fi
315.B
316conf.rc
317Whether ~/.irbrc is read or not.
8dd08261 318.TP
319.fi
320.B
321conf.use_prompt = true/false
322Prompting or not.
8dd08261 323.TP
324.fi
325.B
326conf.use_readline = true/false/nil
327Whether readline is used or not.
328true: uses
329false: doen't use
330nil: intends to use readline except for inf\-reuby\-mode (default)
8dd08261 331.TP
332.fi
333.B
334conf.verbose=T/F
335Whether verbose messages are display or not.
8dd08261 336.TP
337.fi
338.B
339cb, irb_change_binding [obj]
340Enter new binding which has a distinct scope of local variables.
341If obj is given, obj will be self.
8dd08261 342.TP
343.fi
344.B
345irb [obj]
346Invoke subirb. If obj is given, obj will be self.
8dd08261 347.TP
348.fi
349.B
350jobs, irb_jobs
351List of subirb
8dd08261 352.TP
353.fi
354.B
355fg n, irb_fg n
356Switch into specified subirb. The following is candidates of n:
8dd08261 357.nf
358\& irb number
359\& thhread
360\& irb object
361\& self(obj which is specified of irb obj)
362.fi
8dd08261 363.TP
364.fi
365.B
366kill n, irb_kill n
367Kill subirb. The means of n is as same as the case of irb_fg.
368.SH System variable
92275170 369
8dd08261 370.PP
92275170 371
372.TP
8dd08261 373.fi
92275170 374.B
375_
376The latest value of evaluation (it is local)
8dd08261 377.SH Session Example
92275170 378
8dd08261 379.PP
380.nf
92275170 381\& $ irb1.8
8dd08261 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)
386\& nil
387\& irb#1(main):002:0> fg 0 # switch job
388\& nil
389\& irb(main):002:0> class Foo;end
390\& nil
391\& irb(main):003:0> irb Foo # invoke subirb which has the
392.fi
393.nf
394\& # context of Foo
395.fi
396.nf
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
400\& nil
401\& irb#2(Foo):004:0> fg 0 # switch job
402\& nil
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)
407\& nil
408\& irb(main):005:0> Foo.instance_methods # Foo#foo is defined asurely
409\& ["foo"]
410\& irb(main):006:0> fg 2 # switch job
411\& nil
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
415\& nil
416\& irb#2(Foo):010:0> Foo.instance_methods
417\& ["bar", "foo"]
418\& irb#2(Foo):011:0> fg 0
419\& nil
420\& irb(main):007:0> f = Foo.new
421\& #<Foo:0x4010af3c>
422\& irb(main):008:0> irb f # invoke subirb which has the
423.fi
424.nf
425\& # context of f (instance of Foo)
426.fi
427.nf
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)
433\& nil
434\& irb#3(#<Foo:0x4010af3c>):002:0> foo # evaluate f.foo
435\& 1nil
436\& irb#3(#<Foo:0x4010af3c>):003:0> bar # evaluate f.bar
437\& barnil
438\& irb#3(#<Foo:0x4010af3c>):004:0> kill 1, 2, 3# kill job
439\& nil
440\& irb(main):009:0> jobs
441\& #0\->irb on main (#<Thread:0x400fb7e4> : running)
442\& nil
443\& irb(main):010:0> exit # exit
8dd08261 444.fi
445.SH Restrictions
92275170 446
8dd08261 447.PP
448Because irb evaluates the inputs immediately after the imput is
449syntactically completed, irb gives slight different result than
450directly use ruby. Known difference is pointed out here.
451.SH Declaration of the local variable
92275170 452
8dd08261 453.PP
454The following causes an error in ruby:
92275170 455
8dd08261 456.nf
457\& eval "foo = 0"
458\& foo
459\& \-\-
460\& \-:2: undefined local variable or method `foo' for #<Object:0x40283118> (NameError)
461\& \-\-\-
462\& NameError
463.fi
92275170 464
8dd08261 465Though, the above will successfully done by irb.
92275170 466
8dd08261 467.nf
468\& >> eval "foo = 0"
469.fi
470.nf
471\& => 0
472\& >> foo
473\& => 0
474.fi
92275170 475
8dd08261 476Ruby evaluates a code after reading entire of code and determination
477of the scope of local variables. On the other hand, irb do
478immediately. More precisely, irb evaluate at first
92275170 479
8dd08261 480.nf
481\& evel "foo = 0"
482.fi
92275170 483
8dd08261 484then foo is defined on this timing. It is because of this
485incompatibility.
486If you'd like to detect those differences, begin...end can be used:
92275170 487
8dd08261 488.nf
489\& >> begin
490\& ?> eval "foo = 0"
491\& >> foo
492\& >> end
493\& NameError: undefined local variable or method `foo' for #<Object:0x4013d0f0>
494\& (irb):3
495\& (irb_local_binding):1:in `eval'
496.fi
497.SH Here\-document
92275170 498
8dd08261 499.PP
500Implementation of Here\-document is incomplete.
501.SH Symbol
92275170 502
8dd08261 503.PP
504Irb can not always recognize a symbol as to be Symbol. Concretely, an
505expression have completed, however Irb regard it as continuation line.
506
This page took 0.092946 seconds and 4 git commands to generate.