RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Ruby Developers Get Productive with NetBeans' Ruby Pack : Page 2

The simplicity and power of Ruby and Ruby on Rails have become renowned. However, finding a suitable IDE has sometimes left them wanting. With NetBeans, Ruby developers may find the productivity gains of their language are finally matched by an IDE.

Ruby Project Creation
The NetBeans New Project wizard offers Ruby developers the ability to create a base Ruby or Ruby on Rails application. Options provide the ability to create the project from scratch or from existing source.

NetBeans has become popular for offering many types of example applications that can get people just starting out with the IDE up to speed quickly. You can load these sample applications from the New Project wizard. Unfortunately, NetBeans includes only one Ruby example—a Ruby on Rails WebLog application (see Figure 1).

When creating a standard Ruby application, the wizard just creates the project structure with a nearly empty rakefile and main Ruby code file. Rake is Ruby's make facility (more on Rake is available here) which NetBeans can employ. In the case of a Rails application, however, the wizard creates a collection of folders, files, and standard generator scripts to support a functioning Web application. More on Rails applications is covered later.

As to be expected, NetBeans recognizes Ruby file types (.rb, .rhtml) and provides a "Ruby" file icon and appropriate file actions to the files from right click menus. Also, double-clicking any of the Ruby files in the list of project files opens the file in a Ruby-aware editor.

Figure 1. Load Example Apps: Example applications to explore and learn from, such as the Ruby on Rails WebLog, are also loaded through NetBeans New Project Wizard.
Figure 2. Ruby Code Folds: As with other programming languages, Ruby editors allow code blocks like modules, classes and methods to be folded to help allow developers to shrink and hide certain elements of the file while focusing on others.

Standard Editing Capabilities Plus
NetBeans Ruby Pack offers the standard code-editing conveniences that developers have come to expect and rely on. NetBeans' Ruby Pack includes the following standard features and work, for the most part, identically to NetBeans' Java-editing features.

  • Keyword/code-completion: Hit Ctrl-Space when typing code (keyword, class, method, etc.) and the editor offers code completion capability. Importantly, code completion/suggestion also works for regular expressions.
  • Parameter Hints: Hit Alt-P when calling a method and the editor offers parameter options.
  • Code Fold: Modules, classes, and methods can be collapsed into margin icons and {...} notation in the code (see Figure 2).
  • Background Syntax Checking: Background processes parse the code and highlight syntax errors.
  • Syntax Highlighting: Keywords, variables, classes, unused references, etc. are all color/font coded to highlight various elements in the code files.
  • Occurrences Highlighting: Placing the cursor on any reference (variable, method, or class) causes other references/declarations of the reference to be highlighted (see Figure 3).

  • Figure 3. Occurrence Highlighting: In this example, all occurrences of the height attributes are highlighted when the height attribute is selected.
    Figure 4. Navigator Window: This allows you to see the makeup of a Ruby file and quickly navigate to a particular method, declaration, etc.

  • Smart Selection: By pressing Alt-Shift-Up Arrow or Alt-Shift-Down Arrow, the editor will select larger or smaller code blocks around the cursor.
  • Jump to Source: Either hit alt-g or right click and select Go to —>Declaration on any class, method, variable, etc. reference and jump to its declaration.
  • Smart Indenting and Reformatting: End-statements are automatically added and the next line of code is indented properly after you hit enter when adding new class, method, or other block code (if, case, etc.). What makes this a little more interesting in Ruby is that the application of ( ) and { } are looser, but the editor manages these differences just fine. Reformatting the entire code file (Ctrl-Shift-F in a file) follows the same indentation rules.
  • Ruby Identifier Selection: The editor is aware of special Ruby notation, so double clicking to select a symbol will include identifier characters like @, $, etc. as part of the selection where appropriate.
  • Pair Matching: Along the same lines as completing a class, method, etc. definition with an end statement, the editor will detect and add a matching closing parentheses, brace, bracket, string delimiter, regular expression delimiter, etc. Whenever the cursor rests behind one of these characters it highlights the matching delimiter.
  • Navigator Window: The Navigator window displays the modules, classes, methods, attributes, etc. of the Ruby file (see Figure 4). Double clicking on any element in the Navigator takes you to the element in the Rudy source code. Filter buttons on the bottom of the navigator filter elements just as in Java editing.
  • Support for RDoc: The editor properly shows and highlights RDoc comment tags/directives. Formatting tags can also be used in the code completion documentation help (see Figure 5).

  • Figure 5. RDOC Comments: RDoc comments added to source code.
    Figure 6. Ruby Templates: Currently only a few templates exist for NetBeans. NetBeans creators are asking for developers to contribute templates on the Ruby Pack Wiki.

  • Code Templates: A few Ruby code templates are available for some basic tasks (see Figure 6). For example, a template exists for creating a new Ruby class. As the Wiki site suggests, more templates are needed. Perhaps Sun will make more templates available before the final release.
  • Instant Rename: Hitting Ctrl-R or right clicking and selecting Instant Rename on any variable/attribute name allows you to rename the variable and all references.
Application Execution
Both standard Ruby applications and Rails applications can be executed and tested from the IDE. Breakpoints can be set on the code and applications can also be executed in debug mode to step through the code and watch variables (see Figure 7).

Figure 7. Breakpoints and Debugging: Breakpoints are added by clicking on the far left gray bar of Ruby code editors. Code execution is stopped at the breakpoints during debugging, which allows you to step through the code and explore the variables/code stack.
Figure 8. Interactive Ruby Shell: This window allows you to enter and test code in an interactive mode.

Ruby's interactive development nature is, however, kept alive through the addition of an Interactive Ruby Shell (IRB) window. The IRB window is available from NetBeans Window—>Other menu options. The IRB window allows you to write and test code dynamically (see Figure 8).

Rails applications run on a built-in WEBrick server. Requests to run the application will display on the browser that hits the WEBrick server. Again, more on NetBeans and Rails is offered below.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date