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