RubyonNetBeans6

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

File:New Ruby Application

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

File: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".

File: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

File: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.

File: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

File: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.

File: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

File:Installing Ruby Gems

File:Installing Ruby Gems File: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

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo