Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage Articles NetBeans: Ruby Developer's New Best Friend

NetBeans: Ruby Developer's New Best Friend

This item in japanese


NetBeans is well-known as a popular and feature-rich Java IDE that was open-sourced by Sun Microsystems in 2000. And with a continuously growing user community, it is considered today to be one of the major IDEs in the field. In 2007, NetBeans began an expansion of its feature set to support many non-Java languages, including Ruby.

In this series of articles, you will discover various ways that NetBeans can make a Ruby developer's life easier and some of the features that are not available in other IDEs. We'll also cover the background of the Ruby tooling project and provide necessary information about how to get the bits, configure the IDE, and the possible ways of contributing to the project.

Why is Sun investing in Ruby?

It may come as a surprise that Sun Microsystems is investing so heavily in Ruby tools, after all, Ruby is a competitor to Java as a language. To understand Sun's motivation, we need to look at Java as a platform. Java is not only a programming language but also a Virtual Machine and a set of APIs. Today, the Java Virtual Machine (JVM) supports many different languages, unlike in the past. That JVM is no longer only about Java is emphasized by the fact that Sun bundles the Rhino JavaScript interpreter in JDK 6.

Sun recognized the value of dynamic languages - Java language is still the best for large scale enterprise applications, but dynamic languages such as Ruby can be very productive in specific areas, such as prototyping, web development or for gluing various applications together. In 2006, Sun hired the main developers of the JRuby project: Thomas Enebo and Charles Oliver Nutter, to further explore ways of integrating Ruby into the Java platform. (JRuby is a Ruby implementation written purely in Java.) The JRuby project reached an important milestone when version 1.0 was released in June 2007.

By using JRuby, developers gain many advantages of the Java platform, such as access to Java APIs and ease of deployment. The Java platform currently provides a large amount of libraries (most of them are open source) so Ruby developers can benefit from accessing these libraries directly from Ruby code if run on top of JRuby. JRuby can bring the Ruby language into places where Ruby could not be used before. Ever thought of running Ruby on a mainframe? JRuby can make it possible. The Java platform has many solutions for solving scalability, security, maintenance, deployment, and other issues of enterprise applications, and again Ruby developers can benefit from these thanks to JRuby.

Sun always provides tooling for its technologies via NetBeans and JRuby is no exception. However, if you are a Ruby or Rails developer and not interested in JRuby at all, you can still use NetBeans. NetBeans Ruby IDE ships with JRuby as the default runtime, but you can change JRuby to native Ruby in the Options dialog - you just need to point NetBeans to your Ruby installation. So NetBeans is interesting both for Java developers who are exploring the dynamic language area and for Ruby/Rails developers who are not interested in Java at all.

Three feature highlights of Ruby support in NetBeans

Let's look at three features that I consider extremely useful when developing with Ruby in NetBeans.

1. Code completion everywhere

Code completion is a context sensitive pop-up that provides users with a selection of the best possible methods, classes or modules. It can be invoked by pressing Ctrl-Space in the editor. Code completion is well-known and loved by Java developers - every modern Java IDE provides it. However, in Ruby creating good completion is a very difficult task because types are not declared in Ruby language. Thus the IDE resorts to heuristics to guess what the types are and provides options in code completion based on its guess.

Code completion shrinks the possible number of options as you type, and you can simply hit Enter to fill in the selected option:

You can see the module for each of the methods and what parameters are accepted by the method. Providing a fast way to fill in the method/class/module name and parameters is only one of many ways that code completion helps. Also extremely useful is the way that code completion shows documentation (RubyDoc) for each of the classes, methods, modules, keywords, etc.

Easy access to documentation is especially useful for beginners or developers who are migrating to Ruby from different languages - you can use code completion to learn the API as you develop. This is a friendlier way to learn a language and its APIs than to study all the details upfront. Plus, many developers prefer to experiment when learning and Ruby's clean language and API can make it easy and fun.

Code completion can also help when you type Require statements:

One of the useful features of code completion in NetBeans is support for regular expressions. Unless you are one of the few who can remember all syntactical options for regular expressions, you will find this very handy:

Similarly, if you can't remember the names or meanings of dollar variables, or what the escape codes that follow a percent sign are, NetBeans will help you:

I have only touched on some of the basic features, but there are many other ways that code completion can make your life easier. When using NetBeans for Ruby development you will definitely discover why Ctrl-Space is guaranteed to become your favorite shortcut!

2. Graphical Ruby debugger

Most Java developers can't imagine their lives without a good debugger. However, debugging in Ruby has been quite a challenge until recently. NetBeans provides a graphical debugger for Ruby, one that is very similar to Java's. You can add breakpoints into your code and run the application in debug mode and it will stop on the first breakpoint as expected. Then you can see useful views such as local and global variables; you can add watches; see the call stack, switch threads, etc. If you hover your mouse cursor over any element in your code, the expression's current value is evaluated and you can see the result instantly.

As you can see in the above screenshot, RHTML debugging is supported as well, and you can easily step through RHTML pages.

3. Ruby refactoring & quick fixes

Refactoring Ruby code until now has tended to painful: if you changed a method name you had to rename all its occurrences. With NetBeans, this process is automated so you can do things such as search for all usages of any method/class/variable in your code or invoke the rename refactoring to change the name of the element. Here's an example of the output of the find usages command:

The rename refactoring lets you change all the references in a different view:

In future versions of NetBeans's Ruby support, there will also be other refactoring available, including features such as extract method, extract local variable and others.

The IDE can sometimes detect variable collisions in code and in cases where the code may not do what the user intended. The IDE can provide a "quick fix", an easy way to correct the code:

In the screenshot above, the block variable name is the same as the local variable name, which will lead to a side effect in the code; the IDE gives you the option of renaming the variable to solve the problem.

Again, these are just some examples of how NetBeans makes the Ruby developer's life easier. I will focus on additional editing features in upcoming articles in this series.

Where to get NetBeans Ruby IDE?

There are several ways to get Ruby support for NetBeans. One way is to visit the NetBeans 6.0 download page and get the full installer, which includes Ruby support:

However, if you prefer to install a minimal version of the Ruby IDE, you can get a daily build from here:

Another option for obtaining Ruby modules is to install the basic Java IDE and then go to the Plugin Manager in the IDE (Tools | Plugin Manager) and let NetBeans download the modules over the network and install them.

Currently, NetBeans's Ruby support is available as a preview. Although we know of many developers who already use it on commercial applications, there are bugs that will be fixed in the final version. If you encounter any bugs, please file them in NetBeans's Issuezilla:

More information

You can find additional information about Ruby support in NetBeans on its wiki page.

We have also recorded several screencasts that highlight various new features: and

Other demos and tutorials are available from the main Ruby documentation page.

In following articles in this series, we will discuss additional features of Ruby support and other topics, such as how to get involved in the project and its future plans. In the meantime, make sure to try out Ruby support in NetBeans. If you develop in Ruby a lot, you may find that NetBeans is the IDE you have been looking for!

Rate this Article


Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

  • Great Process

    by chen sky,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    I like scripting ruby on NB,but there are some troubles.
    The code completion is so dirty.I like Eclipse's code completion style much more.

  • Tor Norbye

    by Ben Loud,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Check out Tor's blog for lots more examples of features:

  • Dynamic Languages - yes, but why Ruby?

    by Zeev B,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    I guess that Sun decided to invest in Ruby because of the big RoR hype in the past couple of years. I think that there is a more suitable dynamic language that has a JVM implementation and a very dedicated community. It is used a lot throughout the industry for example, Google uses it a lot (and it is even used inside Sun).This language arrives with a lot of useful built-in libraries and there are a lot of other open source libraries and frameworks to choose from. It is used to build big web sites such as YouTube and it is also used a lot by system adminitrators that want an easy and productive way to create scripts. You probably guessed by now that I am talking about the Python programming language.
    Although very different from Java I find Python is in tune with the Java culture :
    1. Readability and explicitness - both Java and Python endorse clean readable code that explicitly states what is being done. Ruby reminds me of Perl - a "write only" language
    2. Matureness- Python and Java are of almost the same age. They are mature languages that proved themselves again and again in production systems.
    3. Vibrant community - both platforms have a devoted community and community process.
    4. Open source libraries - both platforms have a lot of libraries and frameworks available (a result of points 2 and 3).
    As a Java developer using a lot of Python/Jython nowadays, I am dissapointed that Sun chose not to invest in supporting this popular and productive programming language. I think that NetBeans is loosing an opportiunity to hook up with this wonderful community which is missing a high quality IDE such as NetBeans.

  • Re: Dynamic Languages - yes, but why Ruby?

    by Evgeny Zislis,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Why would Sun want to invest their efforts into Ruby instead of Python?
    You just write That Python is so similar to Java.
    Well, Ruby is somewhat different from Java ... that may be their reason to choose it.

  • Re: Dynamic Languages - yes, but why Ruby?

    by Zeev B,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    I'm not sure if you are joking or not... I'll assume you are not.

    Python and Java are very different programming languages, just as Ruby and Java. Moreover, Python is much closer to Ruby since they are both dynamic languages.
    I was referring to the Python and Java culture and communities.

    I think that Sun went the Ruby way because of the hype surrounding Ruby-on-Rails and the fact that many "high-profile" Java developers were stating that they are moving to the Ruby camp.
    I know that there are even Sun employees that are working with Python that expressed their interest in seeing support for it in NetBeans.
    I hope that the Ruby support was developed in a way that will allow easy porting to support other popular dynamic languages such as Python.

  • Re: Dynamic Languages - yes, but why Ruby?

    by Paul D,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Best I can tell Sun threw some weight behind Ruby in order to play to the RoR buzz. The dynamic language that appears to offer a best symbiotic fit w/ Java ... Groovy.

  • Re: Dynamic Languages - yes, but why Ruby?

    by Dinko Srkoč,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    About the reasons Python being in tune with the Java culture (as opposed to Ruby):
    1. Readability and explicitness - I am sure one can write unreadable Python or Java code, just as one can write unreadable code in Ruby. Perl did influence Ruby, but the use of Perl style is actually discouraged.
    2. Matureness - Python pre-dates Java by 4 years, first public release of Ruby coincided with the first public release of Java (1995).
    3. Vibrant community - I would say Ruby's community is just as much devoted to the platform as the Java or Python communities are, and it is growing by day.
    4. Open source libraries - the Ruby platform has a lot of libraries (admittedly, less than Java or Python). Moreover, JRuby can easily use Java's extensive set of libraries.

    Even though Ruby may not have the body count behind it as Java or Python, it does have hype. Eventually, that hype will grow into community perhaps just as large as Python's. I would even argue that Jython was recently revived largely in response to/because of Ruby/JRuby success (and call to arms by no other than JRuby's Charles Nutter).
    Finally, there are companies, besides Google, that do use or support Ruby in one way or the other (Sun, Amazon, Yahoo, Twitter).

    To conclude, I don't think Sun chose to support Ruby only because of the big RoR hype, and the suitability of a language is actually in the eye of the beholder.

  • Re: Dynamic Languages - yes, but why Ruby?

    by Zeev B,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    You say "..I don't think Sun chose to support Ruby only because of the big RoR hype..." - so why did Sun chose Ruby?
    It doesn't make sense since they had to invest in developing proper support for it in order to run on the JVM when they could have used Jython which already does this for Python.
    I don't see any technical reason to prefer Ruby over Python or Groovy - it's sounds to me like the hype played a major rule in this decision.

  • Re: Dynamic Languages - yes, but why Ruby?

    by Roman Strobl,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Groovy support in NetBeans is coming, look at:

    Sun chose Ruby over Groovy because at the time the decision was made Groovy wasn't mature yet + there were some other strategical reasons (e.g. size of Ruby community and Solaris developer stack that supports Ruby). Groovy is now ready for mainstream usage and we plan to support it in the next version.

    We are also looking into Python support in the future. PHP support is also coming.

  • awesome

    by John Griffiths,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    can't believe how much it has helped me, much better than Aptana & Eclipse ;-)

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p