Friday Jun 20, 2008
Friday Jun 20, 2008
Accessing the IRB Console from the IDE
The Ruby support in the NetBeans 6.1 IDE includes the Interactive Ruby (IRB) Console. To open the console, choose Window > Other > Ruby Shell from the main menu. The console opens in the bottom window.

The interpreter that is used by the console depends on the main project's Ruby Platform setting (the bold project node in the Projects window is the main project). To see the Ruby Platform setting, right-click on project's node and choose Properties. If your project is a Ruby project, select Run in the Categories pane to see the Ruby Platform setting. You can switch to a different platform, if you want.
The tab for the IRB console window indicates which the interpreter it is using. In the above screenshot, you can see that the IDE is using the Built-In JRuby platform.
To exit from the IRB console, type exit or quit, and close the window.
Using Gems in the IRB Console
Before you can use gems in the IRB, you have to load RubyGems. Most platforms take care of this for you. For those that do not, such as the built-in JRuby platform, you must load it yourself. If you do not load RubyGems, you will see an error similar to the following output.
>> require 'renum'
LoadError: no such file to load -- renum
from (irb):2:in `require'
from (irb):2:in `signal_status'
The quickest way load RubyGems is to type the following statement in the console.
>>
require 'rubygems'
If you do not want to type that every time you open an IRB console, you can
add -rubygems to the Ruby Options text box in the
project's Properties dialog box.

Using .irbrc Files for Common
Settings
Another way to load RubyGems every time you open the console, is to add or
copy over an .irbrc file to the project's top level folder and add
require 'rubygems' to that file. To create an .irbrc
file, right-click the project node and choose New >
Other from the pop-up menu. Select Other in the
Categories pane, select Empty File in the
File Types pane, and click Next. Name the
file .irbrc and click Finish.
If you have IRB settings that you would like applied to all your projects,
such as loading RubyGems, you can put the settings in an .irbrc
file in your home directory. In order to get the IDE to read this file when
opening the IRB console, you must create a HOME system environment
variable (be sure to make it all capital letters) that provides the path to
your home directory, and restart the IDE.
Note that you will not see the .irbrc file in the Projects
window or the Files window. To learn how to configure the IDE so that you can
see this file, see MRHAKI's blog
that shows how.
Using the JRuby IRB Console
The IDE also offers support for the JRuby IRB console. With this console, you get code completion, as shown below. You can type the first few characters and press Tab to see a list of suggestions.

The JRuby IRB console also has a history feature. Pressing the Up-Arrow key scrolls through through the command history and pressing the Down-Arrow key scrolls back. You can press Return to re-execute a command.
To enable the JRuby IRB console, add the following flag to your NetBeans IDE
startup command or add it to the netbeans_default_options entry in
the netbeans-install-dir/etc/netbeans.conf file, and
restart the IDE. One problem with this option, is that you get the JRuby IRB
console, regardless of which platform your project is using.
-J-Dirb.jruby=true
The last paragraph states, "...add the following flag..."
What is the flag to use?
Posted by Thom Parkin on July 02, 2008 at 10:00 AM PDT #
Hi Thom,
Sorry about that. I cut the end off when I pasted into the editor. I have fixed the problem, and added the flag, which is -J-Dirb.jruby=true
Posted by diva#2 on July 02, 2008 at 10:32 AM PDT #
How can I configure Netbeans so it can use JIRB instead of IRB?
Posted by About JIRB on July 12, 2008 at 06:15 PM PDT #
To enable the JRuby IRB console, add the following flag to your NetBeans IDE startup command or add it to the netbeans_default_options entry in the netbeans-install-dir/etc/netbeans.conf file, and restart the IDE. One problem with this option, is that you get the JRuby IRB console, regardless of which platform your project is using.
-J-Dirb.jruby=true
Posted by diva#2 on July 13, 2008 at 10:51 AM PDT #