JIRB1.3(1) | General Commands Manual | JIRB1.3(1) |
jirb1.3 - interactive JRuby
jirb [options]
irb stands for `interactive JRuby'. irb is a tool to execute interactively JRuby expressions read from stdin. Use of jirb is easy if you know JRuby. Executing jirb, prompts are displayed as follows. Then, enter expression of ruby. Input is executed when it is syntacticaly completed.
$ jirb1.3 irb(main):001:0> 1+2 3 irb(main):002:0> class Foo irb(main):003:1> def foo irb(main):004:2> print 1 irb(main):005:2> end irb(main):006:1> end nil irb(main):007:0>
And, Readline extension module can be used with irb. Using Readline is the standard default action if Readline is installed.
jirb reads `~/.irbrc' when it is invoked. If `~/.irbrc' doesn't exist jirb try to read in the order `.irbrc', `irb.rc', `_irbrc' then `$irbrc'. The following is alternative to the command line option. To use them type as follows in a jirb session.
IRB.conf[:IRB_NAME]="irb" IRB.conf[:MATH_MODE]=false IRB.conf[:USE_TRACER]=false IRB.conf[:USE_LOADER]=false IRB.conf[:IGNORE_SIGINT]=true IRB.conf[:IGNORE_EOF]=false IRB.conf[:INSPECT_MODE]=nil IRB.conf[:IRB_RC] = nil IRB.conf[:BACK_TRACE_LIMIT]=16 IRB.conf[:USE_LOADER] = false IRB.conf[:USE_READLINE] = nil IRB.conf[:USE_TRACER] = false IRB.conf[:IGNORE_SIGINT] = true IRB.conf[:IGNORE_EOF] = false IRB.conf[:PROMPT_MODE] = :DEFALUT IRB.conf[:PROMPT] = {...} IRB.conf[:DEBUG_LEVEL]=0 IRB.conf[:VERBOSE]=true
To customize the prompt you set a variable
IRB.conf[:PROMPT]
For example, describe as follows in `.irbrc'.
IRB.conf[:PROMPT][:MY_PROMPT] = { # name of prompt mode :PROMPT_I => nil, # normal prompt :PROMPT_S => nil, # prompt for continuated strings :PROMPT_C => nil, # prompt for continuated statement :RETURN => " ==>%s\n" # format to return value }
Then, invoke irb with the above prompt mode by
$ jirb1.3 --prompt my-prompt
Or add the following in `.irbrc'.
IRB.conf[:PROMPT_MODE] = :MY_PROMPT
Constants PROMPT_I, PROMPT_S and PROMPT_C specifies the format. In the prompt specification, some special strings are available.
%N command name which is running %m to_s of main object (self) %M inspect of main object (self) %l type of string(", ', /, ]), `]' is inner %w[...] %NNi indent level. NN is degits and means as same as printf("%NNd"). It can be omitted %NNn line number. %% %For instance, the default prompt mode is defined as follows: IRB.conf[:PROMPT_MODE][:DEFAULT] = {
The command line option or IRB.conf specify the default behavior of (sub)irb. On the other hand, each conf of in the next sction `6. Command' is used to individually configure (sub)irb. If proc is set to IRB.conf[:IRB_RC], its subirb will be invoked after execution of that proc under giving the context of irb as its argument. By this mechanism each subirb can be configured.
For irb commands, both simple name and `irb_'-prefixed name are prepared.
during input: cancel inputing then return to top level. during execute: abondon current execution.
non inspect mode in math mode.
irb number thhread irb object self(obj which is specified of irb obj)
$ jirb1.3 irb(main):001:0> irb # invoke subirb irb#1(main):001:0> jobs # list of subirbs #0->irb on main (#<Thread:0x400fb7e4> : stop) #1->irb#1 on main (#<Thread:0x40125d64> : running) nil irb#1(main):002:0> fg 0 # switch job nil irb(main):002:0> class Foo;end nil irb(main):003:0> irb Foo # invoke subirb which has the
# context of Foo
irb#2(Foo):001:0> def foo # define Foo#foo irb#2(Foo):002:1> print 1 irb#2(Foo):003:1> end nil irb#2(Foo):004:0> fg 0 # switch job nil irb(main):004:0> jobs # list of job #0->irb on main (#<Thread:0x400fb7e4> : running) #1->irb#1 on main (#<Thread:0x40125d64> : stop) #2->irb#2 on Foo (#<Thread:0x4011d54c> : stop) nil irb(main):005:0> Foo.instance_methods # Foo#foo is defined asurely ["foo"] irb(main):006:0> fg 2 # switch job nil irb#2(Foo):005:0> def bar # define Foo#bar irb#2(Foo):006:1> print "bar" irb#2(Foo):007:1> end nil irb#2(Foo):010:0> Foo.instance_methods ["bar", "foo"] irb#2(Foo):011:0> fg 0 nil irb(main):007:0> f = Foo.new #<Foo:0x4010af3c> irb(main):008:0> irb f # invoke subirb which has the
# context of f (instance of Foo)
irb#3(#<Foo:0x4010af3c>):001:0> jobs #0->irb on main (#<Thread:0x400fb7e4> : stop) #1->irb#1 on main (#<Thread:0x40125d64> : stop) #2->irb#2 on Foo (#<Thread:0x4011d54c> : stop) #3->irb#3 on #<Foo:0x4010af3c> (#<Thread:0x4010a1e0> : running) nil irb#3(#<Foo:0x4010af3c>):002:0> foo # evaluate f.foo 1nil irb#3(#<Foo:0x4010af3c>):003:0> bar # evaluate f.bar barnil irb#3(#<Foo:0x4010af3c>):004:0> kill 1, 2, 3# kill job nil irb(main):009:0> jobs #0->irb on main (#<Thread:0x400fb7e4> : running) nil irb(main):010:0> exit # exit
Because irb evaluates the inputs immediately after the input is syntactically completed, irb gives slight different results than directly using ruby. Known differences are pointed out here.
The following causes an error in ruby:
eval "foo = 0" foo -- -:2: undefined local variable or method `foo' for #<Object:0x40283118> (NameError) --- NameError
Though, the above will successfully done by irb.
>> eval "foo = 0"
=> 0 >> foo => 0
Ruby evaluates a code after reading entire of code and determination of the scope of local variables. On the other hand, irb do immediately. More precisely, irb evaluate at first
evel "foo = 0"
then foo is defined on this timing. It is because of this incompatibility. If you'd like to detect those differences, begin...end can be used:
>> begin ?> eval "foo = 0" >> foo >> end NameError: undefined local variable or method `foo' for #<Object:0x4013d0f0> (irb):3 (irb_local_binding):1:in `eval'
Implementation of Here-document is incomplete.
Irb can not always recognize a symbol as to be Symbol. Concretely, an expression have completed, however Irb regard it as continuation line.
April 2007 |