- Overview
- Installing IronRuby
- Executables and Tools
- Development Environments
- The Power of IronRuby
- Summary
Executables and Tools
IronRuby comes with several different executables and tools. All of them are located under the Bin folder in the IronRuby installation directory.
Table 4.2 lists and describes the executables and tools in the IronRuby Bin folder, and then the following subsections take a closer look at them.
Table 4.2. IronRuby Executables and Tools
File |
Description |
ir.exe |
The main IronRuby executable. It is the IronRuby interpreter file. ir64.exe is for 64-bit systems. |
iirb.bat |
The IronRuby REPL (read-evaluate-print loop) console. |
igem.bat |
Used to work install and manage RubyGems. See Chapter 8, "Advanced Ruby." for more information about RubyGems. |
irackup.bat |
Runs Rack, which is a Ruby framework that simplifies the way of interacting with different Ruby web servers. |
irake.bat |
Executes the Rake. See Chapter 8 for more about Rake. |
irails.bat |
Used to create a Ruby on Rails application. See Chapter 14, "Ruby On Rails." for more about Ruby on Rails. |
irdoc.bat |
Runs RDoc, which is a Ruby tool to create formatted documentation out of Ruby code. The output can be plain text or a formatted HTML. |
iir.bat |
Ruby tool to read the textual documentation of Ruby objects. (The documentation is created by RDoc.) |
The IronRuby Interpreter (ir.exe)
The IronRuby interpreter is the heart of IronRuby. Everything goes through it. For example, all the tools mentioned in Table 4.2 eventually run ir.exe.
The IronRuby interpreter can run Ruby files as well as a REPL console. These are two different modes, and so I discuss each of them separately.
REPL Console Mode
The REPL console mode opens a console where you can write code and execute it immediately.
To run IronRuby in the REPL console mode, follow these steps:
- Click Start > Run.
- Type cmd and click OK. The command prompt opens.
- If you haven't added the IronRuby installation folder to the Path system variable, navigate to <installation folder>\Bin. If you have updated the Path system variable, skip this step.
- Type ir and press Enter.
The IronRuby REPL console opens. You can now write Ruby code there (for example, "puts 'hello world'") or even write whole classes and use them.
The format is simple. Each line where you can write a Ruby statement starts with a triple right-angle sign (>>>). If the line is not assumed to be continued (like method or class definitions), when you press Enter its output (if any) is printed to the console and the next line contains the return value of the statement preceded by an equal or greater than sign (=>). If the line is assumed to be continued, the next statement line starts with an ellipsis (...).
Figure 4.6 shows an REPL console session.
Figure 4.6 A screenshot of an IronRuby REPL console session.
The REPL console mode has some specific command-line switches that can be used when running ir.exe. Table 4.3 lists and describes the switches. Be aware that the switches are case sensitive.
Table 4.3. ir.exe REPL Mode Command-Line Switches
Switch |
Description |
- |
Makes the REPL console colorful. |
X:ColorfulConsole |
Prompt signs such as >>> and ... appear gray, errors red, and warnings yellow; messages (like the banner on top) appear cyan, and all other output uses the default console output color. |
These are the REPL mode-only switches. All other switches appear on Table 4.4, and some can be used in this mode, too.
Table 4.4. ir.exe Command-Line Arguments for File Execution Mode
Argument |
Description |
-d |
Debug mode. Allows using breakpoints in Ruby code with the Visual Studio debugger. |
-e "command" |
Executes the command and exits. Several -e arguments are allowed. When used, the file path should not be passed and will be ignored if it exists. For example: ir -e "str = 'Hello World'" -e "puts str" |
-I "directory" |
Includes the given directory in the $LOAD_PATH variable. This means that it will be included in the search paths for required libraries. |
-r "library" |
Requires the library before executing the file. For example: ir -r "csv" test.rb |
-v |
Prints the IronRuby version on the first line. |
-w |
Turns on warnings in the default level (verbose). |
-W[level] |
Sets the warning level. 0 = silence, 1 = medium, 2 = verbose (default). For example: ir -W1 test.rb |
-K[kcode] |
Specifies KANJI (Japanese) code set. E or e = EUC, S or s = SJIS, U or u = UTF8. For example: ir -KU test.rb |
-trace |
Enables Ruby tracing capabilities. |
-profile |
Enables profiling. When this switch exists, a profile.log file will be added to the directory of the executed file with profiling information about the latest execution. |
-18 |
Run IronRuby in Ruby 1.8 compatibility mode (default), Ruby 1.9, or Ruby 2.0 compatibility mode accordingly. Ruby 2.0 doesn't currently exist, so this switch is for future release only. |
-X:ExceptionDetail |
In this mode, every exception is presented with a full call stack. |
-X:NoAdaptiveCompilation |
Disables adaptive compilation feature. This affects performance (for the worse). |
-X:PassExceptions |
In this mode, exceptions are not caught by the interpreter. This means that in case of an exception with no handling in the script, the application crashes. |
-X:PrivateBinding |
Enables binding to private members of CLR objects. Chapter 9, ".Net Interoperability Fundamentals," discusses the uses of this switch. |
-X:ShowClrExceptions |
When this mode is on, a CLR exception part is added to every exception with full exception details (the exception.ToString output). |
-X:CompilationThreshold |
Specifies the number of iterations before the interpreter starts compiling the code. Should be followed by a number. Note that this switch can affect performance dramatically. Hence it is not recommended to use it when not needed. |
-h |
Shows all available command-line arguments with a short description. When this exists, the file or REPL console does not run. |
File Execution Mode
This mode executes a given file. Its format is as follows:
ir [options] [file path] [file arguments]
All switches and ir.exe command-line arguments should be placed before the file path. Otherwise, they will be considered arguments of the file and will be passed to it rather than to the interpreter.
The simplest way to execute an IronRuby file is by passing only its path to the interpreter. For example, the next command executes the file test.rb, which is located within the current directory:
ir test.rb
Along with this way, IronRuby provides several command-line arguments that affect the way the code executes. Table 4.4 lists and describes available arguments for the ir.exe file execution mode.