[RSS]

Introduction

The aim of this article is to acquaint you with Ruby development on NetBeans 6. Specifically, I have used JRuby for development purpose here. However. the steps outlined here are applicable elsewhere as well. If you want to use the native Ruby interpreter, please refer to this link

I assume a basic knowledge of Ruby, so this article can be equally useful if you are planning to write your second or third program. In the same breath, this guide won't make you the best Ruby programmer around. You are kindly requested to refer to Programming Ruby The Pragmatic Programmer's Guide for acquiring some neat Ruby skills

Installing NetBeans

Before we get started download the latest development version of NetBeans 6 from here. Please download one of the versions that includes Ruby support.

"Hello World" and more..

Adhering with the tradition we shall start of saying "Hello World" from Ruby:
  • Go to File - > New Project -> Ruby and select Ruby Application

New Ruby Application

  • Then enter a Project Name and Location in the next Dialog Box

Project Name and Location

  • Assuming you have done everything correct so far, next you will get the project window, along with the sample Ruby script "main.rb".

Hello World from Ruby

  • To see the output of this simple Ruby project, you have to Run the project. You do this in NetBeans using the menu item Run -> Main Project or F6. You should see a "Hello World" in the Output window

Output Window

Project Explorer

Let is now try to understand the project explorer window that is displayed at the Left side of the Ruby project we just created.

Project Explorer

The Project Explorer basically helps you keep track of your Project files - Source files and Test files.

  1. Under the Source Files, you have all your Ruby source scripts (*.rb) and the RakeFile (Rakefile.rb) file. Refer here for more on Rake and Rakefiles.
  1. Under the Test Files, you have all the Ruby Unit test files that you have written (More on this later)

Adding a new Class

Let us now extend our "Hello Ruby" project to add a new Class. Right Click on the "Source Files" in the project explorer and select New -> Ruby Class. Subsequently enter the new Class name, say Fruit

Adding a new Ruby Class

The class Fruit is created with the initialize function:

class Fruit
  
  def initialize()
  
  end
   
end

For more on initialize and other Object Oriented Features of Ruby refer this link

Adding a new Ruby Script

You can also add a new Ruby script (not a class) using similar steps above

Working with Ruby Gems

RubyGems is a system for managing Ruby software libraries. For a comprehensive overview of the topic consult the links:

  1. http://www.linuxjournal.com/article/8967
  2. http://www.rubygems.org

NetBeans 6 has a comprehensive manager for Ruby Gems which allows to Install, Update, Remove Ruby Gems. Go to Tools->Ruby Gems. The window below shows the Installed Ruby Gems in a default NetBeans Installation.

Installed Ruby Gems

Installing new RubyGems

Go to Tools->Ruby Gems and select the "New Gems" TAB. Select the appropriate RubyGem and click on the Install button

Installing Ruby Gems

Installing Ruby Gems
Installing Ruby Gems

Conclusion

This will hopefully get you Started with Native Ruby on NetBeans. Ideally, I would also like to cover the following topics sometime soon:

  1. Unit Testing for Ruby
  2. Working with CVS/SVN Repositories of Ruby Projects
  3. Working with other NetBeans Ruby Features.

If anyone would like to contribute any of the above, do contact me or just do the EDIT here :)

Links to Further Information

These links will help you to explore jRuby, Ruby on Rails and extending Ruby:

Also, check out same "in-progress" documents on Ruby :

- By Amit Kumar Saha

Attachments

Screenshot-1.png Info on Screenshot-1.png 53223 bytes
Screenshot-2.png Info on Screenshot-2.png 39597 bytes
Screenshot-3.png Info on Screenshot-3.png 46682 bytes
Screenshot-4.png Info on Screenshot-4.png 9837 bytes
Screenshot-6.png Info on Screenshot-6.png 32994 bytes
gems1.png Info on gems1.png 15310 bytes
gems2.png Info on gems2.png 13848 bytes
project-explorer.png Info on project-explorer.png 7685 bytes
ruby-gems-1.png Info on ruby-gems-1.png 58286 bytes
rubygems.png Info on rubygems.png 80938 bytes