1
irb -- interactive ruby
2
$Release Version: 0.9 $
4
$Date: 2007-02-13 08:01:19 +0900 (Tue, 13 Feb 2007) $
5
by Keiju ISHITSUKA(keiju@ishitsuka.com)
6
by gotoken-san who is original translater from japanese version
11
irb stands for `interactive ruby'. irb is a tool to execute interactively
12
ruby expressions read from stdin.
20
Use of irb is easy if you know ruby. Executing irb, prompts are
21
displayed as follows. Then, enter expression of ruby. A input is
22
executed when it is syntacticaly completed.
27
irb(main):002:0> class Foo
28
irb(main):003:1> def foo
29
irb(main):004:2> print 1
35
And, Readline extesion module can be used with irb. Using Readline
36
is the standard default action if Readline is installed.
40
irb.rb [options] file_name opts
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
-Kc same as `ruby -Kc'
46
-r load-module same as `ruby -r'
47
--verbose command input is echoed(default)
48
--noverbose command input isn't echoed
49
--echo commands are echoed immediately before execution(default)
50
--noecho commands aren't echoed immediately before execution
51
--inspect uses `inspect' for output (the default except bc mode)
52
--noinspect doesn't uses inspect for output
53
--readline uses Readline extension module
54
--noreadline doesn't use Readline extension module
56
--prompt-mode prompt-mode
57
switches prompt mode. Pre-defined prompt modes are
58
`default', `simple', `xmp' and `inf-ruby'
60
--inf-ruby-mode uses prompt appreciate for inf-ruby-mode on emacs.
61
Suppresses --readline.
62
--simple-prompt simple prompt mode
64
--tracer display trace for each execution of commands.
66
displayes backtrace top n and tail n. The default
68
--irb_debug n sets internal debug level to n (It shouldn't be used)
69
-v, --version prints the version of irb
73
irb reads `~/.irbrc' when it is invoked. If `~/.irbrb' doesn't exist
74
irb try to read in the order `.irbrc', `irb.rc', `_irbrc' then `$irbrc'.
76
The following is altanative to the command line option. To use them
77
type as follows in an irb session.
79
IRB.conf[:IRB_NAME]="irb"
80
IRB.conf[:MATH_MODE]=false
81
IRB.conf[:USE_TRACER]=false
82
IRB.conf[:USE_LOADER]=false
83
IRB.conf[:IGNORE_SIGINT]=true
84
IRB.conf[:IGNORE_EOF]=false
85
IRB.conf[:INSPECT_MODE]=nil
86
IRB.conf[:IRB_RC] = nil
87
IRB.conf[:BACK_TRACE_LIMIT]=16
88
IRB.conf[:USE_LOADER] = false
89
IRB.conf[:USE_READLINE] = nil
90
IRB.conf[:USE_TRACER] = false
91
IRB.conf[:IGNORE_SIGINT] = true
92
IRB.conf[:IGNORE_EOF] = false
93
IRB.conf[:PROMPT_MODE] = :DEFALUT
94
IRB.conf[:PROMPT] = {...}
95
IRB.conf[:DEBUG_LEVEL]=0
96
IRB.conf[:VERBOSE]=true
100
To costomize the prompt you set a variable
104
For example, describe as follows in `.irbrc'.
106
IRB.conf[:PROMPT][:MY_PROMPT] = { # name of prompt mode
107
:PROMPT_I => nil, # normal prompt
108
:PROMPT_S => nil, # prompt for continuated strings
109
:PROMPT_C => nil, # prompt for continuated statement
110
:RETURN => " ==>%s\n" # format to return value
113
Then, invoke irb with the above prompt mode by
115
% irb --prompt my-prompt
117
Or add the following in `.irbrc'.
119
IRB.conf[:PROMPT_MODE] = :MY_PROMPT
121
Constants PROMPT_I, PROMPT_S and PROMPT_C specifies the format.
122
In the prompt specification, some special strings are available.
124
%N command name which is running
125
%m to_s of main object (self)
126
%M inspect of main object (self)
127
%l type of string(", ', /, ]), `]' is inner %w[...]
128
%NNi indent level. NN is degits and means as same as printf("%NNd").
133
For instance, the default prompt mode is defined as follows:
135
IRB.conf[:PROMPT_MODE][:DEFAULT] = {
136
:PROMPT_I => "%N(%m):%03n:%i> ",
137
:PROMPT_S => "%N(%m):%03n:%i%l ",
138
:PROMPT_C => "%N(%m):%03n:%i* ",
142
RETURN is used to printf.
144
== Configurating subirb
146
The command line option or IRB.conf specify the default behavior of
147
(sub)irb. On the other hand, each conf of in the next sction `6. Command'
148
is used to individually configurate (sub)irb.
150
If proc is set to IRB.conf[:IRB_RC], its subirb will be invoked after
151
execution of that proc under giving the context of irb as its
152
aregument. By this mechanism each subirb can be configurated.
156
For irb commands, both simple name and `irb_'-prefixed name are prepared.
158
--- exit, quit, irb_exit
161
--- conf, irb_context
162
Displays current configuration. Modifing the configuration is
163
achieved by sending message to `conf'.
165
--- conf.eval_history = N
166
Sets execution result history.
167
N is a integer or nil. If N > 0, the number of historys is N.
168
If N == 0, the number of historys is unlimited. If N is nill,
169
execution result history isn't used(default).
171
--- conf.back_trace_limit
172
Sets display lines of backtrace as top n and tail n.
173
The default value is 16.
175
--- conf.debug_level = N
176
Sets debug level of irb.
178
--- conf.ignore_eof = true/false
179
Whether ^D (control-d) will be ignored or not.
180
If false is set, ^D means quit.
182
--- conf.ignore_sigint= true/false
183
Whether ^C (control-c) will be ignored or not.
184
If false is set, ^D means quit. If true,
185
during input: cancel inputing then return to top level.
186
during execute: abondon current execution.
188
--- conf.inf_ruby_mode = true/false
189
Whether inf-ruby-mode or not. The default value is false.
191
--- conf.inspect_mode = true/false/nil
192
Specifies inspect mode.
193
true: display inspect
195
nil: inspect mode in non math mode,
196
non inspect mode in math mode.
199
Whether bc mode or not.
201
--- conf.use_loader = true/false
202
Whether irb's own file reader method is used when load/require or not.
203
This mode is globaly affected (irb wide).
206
prompt for a continuating statement (e.g, immediately after of `if')
212
prompt for a continuating string
215
Whether ~/.irbrc is read or not.
217
--- conf.use_prompt = true/false
220
--- conf.use_readline = true/false/nil
221
Whether readline is used or not.
224
nil: intends to use readline except for inf-ruby-mode (default)
226
#--- conf.verbose=T/F
227
# Whether verbose messages are display or not.
229
--- cws, chws, irb_change_workspace [obj]
230
obj will be self. If obj is omitted, self will be home-object, or
231
the main object of first started irb.
233
--- pushws, irb_pushws, irb_push_workspace [obj]
234
same as UNIX-shell command pushd.
236
--- popws, irb_popws, irb_pop_workspace
237
same as UNIX-shell command popd
240
Invoke subirb. If obj is given, obj will be self.
246
Switch into specified subirb. The following is candidates of n:
251
self(obj which is specified of irb obj)
253
--- kill n, irb_kill n
254
Kill subirb. The means of n is as same as the case of irb_fg.
256
--- souce, irb_source path
257
This is a like UNIX-shell command source. evaluate script in path
260
--- irb_load path, prev
261
irb-version of Ruby's load.
265
--- _ The latest value of evaluation (it is local)
266
--- __ The history of evaluation values.
267
__[line_no] return an evaluation value of line number<line_no>. If
268
line_no is a negative, return value before -<line_no> from latest
274
irb(main):001:0> irb # invoke subirb
275
irb#1(main):001:0> jobs # list of subirbs
276
#0->irb on main (#<Thread:0x400fb7e4> : stop)
277
#1->irb#1 on main (#<Thread:0x40125d64> : running)
279
irb#1(main):002:0> fg 0 # switch job
281
irb(main):002:0> class Foo;end
283
irb(main):003:0> irb Foo # invoke subirb which has the
285
irb#2(Foo):001:0> def foo # define Foo#foo
286
irb#2(Foo):002:1> print 1
287
irb#2(Foo):003:1> end
289
irb#2(Foo):004:0> fg 0 # switch job
291
irb(main):004:0> jobs # list of job
292
#0->irb on main (#<Thread:0x400fb7e4> : running)
293
#1->irb#1 on main (#<Thread:0x40125d64> : stop)
294
#2->irb#2 on Foo (#<Thread:0x4011d54c> : stop)
296
irb(main):005:0> Foo.instance_methods # Foo#foo is defined asurely
298
irb(main):006:0> fg 2 # switch job
300
irb#2(Foo):005:0> def bar # define Foo#bar
301
irb#2(Foo):006:1> print "bar"
302
irb#2(Foo):007:1> end
304
irb#2(Foo):010:0> Foo.instance_methods
306
irb#2(Foo):011:0> fg 0
308
irb(main):007:0> f = Foo.new
310
irb(main):008:0> irb f # invoke subirb which has the
311
# context of f (instance of Foo)
312
irb#3(#<Foo:0x4010af3c>):001:0> jobs
313
#0->irb on main (#<Thread:0x400fb7e4> : stop)
314
#1->irb#1 on main (#<Thread:0x40125d64> : stop)
315
#2->irb#2 on Foo (#<Thread:0x4011d54c> : stop)
316
#3->irb#3 on #<Foo:0x4010af3c> (#<Thread:0x4010a1e0> : running)
318
irb#3(#<Foo:0x4010af3c>):002:0> foo # evaluate f.foo
320
irb#3(#<Foo:0x4010af3c>):003:0> bar # evaluate f.bar
322
irb#3(#<Foo:0x4010af3c>):004:0> kill 1, 2, 3# kill job
324
irb(main):009:0> jobs
325
#0->irb on main (#<Thread:0x400fb7e4> : running)
327
irb(main):010:0> exit # exit
332
Because irb evaluates the inputs immediately after the imput is
333
syntactically completed, irb gives slight different result than
334
directly use ruby. Known difference is pointed out here.
337
== Declaration of the local variable
339
The following causes an error in ruby:
344
-:2: undefined local variable or method `foo' for #<Object:0x40283118> (NameError)
348
Though, the above will successfully done by irb.
355
Ruby evaluates a code after reading entire of code and determination
356
of the scope of local variables. On the other hand, irb do
357
immediately. More precisely, irb evaluate at first
361
then foo is defined on this timing. It is because of this
364
If you'd like to detect those differences, begin...end can be used:
370
NameError: undefined local variable or method `foo' for #<Object:0x4013d0f0>
372
(irb_local_binding):1:in `eval'
376
Implementation of Here-document is incomplete.
380
Irb can not always recognize a symbol as to be Symbol. Concretely, an
381
expression have completed, however Irb regard it as continuation line.
385
% Begin Emacs Environment