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