IRB is an interactive Ruby interface. You can use IRB to debug, run, and experiment Ruby.Code.
IRB command line
The command syntax of IRB is as follows:
IRB [Option] [RUBY script] [Script Parameters]
Common options include:
- -D
Set debugging options
- -Prompt
Prompt mode: NULL, default, classic, simple, XMP, and INF-Ruby
- -I
Specify the $ load_path directory
You can follow the options to execute the ruby script and its parameters.
After IRB is started, the following interface is displayed:
D: \> IRB
IRB (main ):
001
:
0
>
"Hello World"
. Upcase
=>
"Hello World"
IRB (main ):
002
:
0
>
3
+
IRB (main ):
003
:
0
*
4
=>
7
IRB (main ):
004
:
0
> Puts
"Me"
. Capitalize
Me
=>
Nil
IRB (main ):
005
:
0
> Exit
D: \>
Here, "IRB (main): 001: 0>" is the default IRB prompt. You can choose a different style or custom one. In the prompt, IRB indicates the session name and (main) indicates the top-level object of the session. If you start a session in IRB, you can pass in the top-level object of different objects, and the prompt will change accordingly.
D: \> irbirb (main): 001: 0> irbirb #1 (main): 001: 0> IRB "another" IRB #2 (another): 001: 0> jobs => #0-> IRB on main (# <thread: 0x34cc748>: Stop) #1-> IRB #1 on main (# <thread: 0x3a49e8c>: stop) #2-> IRB #2 on another (# <thread: 0x3a43a78>: running)
In the prompt, 001: 0 indicates the row number and indentation level. If the syntax of a row is not completed, ">" is displayed as "*", indicating that the row is resumed.
IRB configuration and Enhancement
At startup, IRB reads configuration information from multiple locations, which are:
- ~ /. Irbrc
Main directory. irbrc file (for windows, the main directory location is as follows: \ Users \ your-user)
- . Irbrc
The. irbrc file in the current directory
- IRB. RC
IRB. RC file in the current directory
- $ Irbrc
Environment Variable irbrc points to the file
IRB has many configurations, including TAB filling and auto indent.
Tab completion
In IRB, you can enter a part of the command/syntax and press the tab to add the unentered part. If there are multiple options, you need to press tab again (double-click tab) to display an optional list. You can continue to enter some characters and complete them through tab. (Tab completion is a feature derived from Unix/Linux and is now supported by command lines in windows .)
Tab completion is completed based on the IRB Readline module and the "IRB/completion" library. By default, the Readline module is loaded. You only need to load the "IRB/completion" library. It can be loaded through the command line, or in ~ /. Irbrc:
Require
'Irb/completion'
Automatic indent Mode
It is automatically indented when input according to the indentation level of the syntax. In ~ /. The irbrc configuration is:
IRB. conf [: auto_indent] =
True
Disable object Check Mode
by default, IRB enables the object check mode, that is, when the object is displayed, the content of the object is also dumped. If it feels messy, you can disable it:
IRB. conf [: inspect_mode] =
false