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
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
- Then enter a Project Name and Location in the next Dialog Box
- Assuming you have done everything correct so far, next you will get the project window, along with the sample Ruby script "main.rb".
- 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
Let is now try to understand the project explorer window that is displayed at the Left side of the Ruby project we just created.
The Project Explorer basically helps you keep track of your Project files - Source files and Test files.
- 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.
- 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
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:
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.
Installing new RubyGems
Go to Tools->Ruby Gems and select the "New Gems" TAB. Select the appropriate RubyGem and click on the Install button
This will hopefully get you Started with Native Ruby on NetBeans. Ideally, I would also like to cover the following topics sometime soon:
- Unit Testing for Ruby
- Working with CVS/SVN Repositories of Ruby Projects
- 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