Ruby Hints And Quick Fixes

The Ruby editor supports pluggable quickfixes and hints.

More information about this is available in this blog entry and this blog entry (the material will be added to the wiki soon).

Ideas for additional quick fixes can be found in RubyCodeIdeas - please contribute your ideas there or via the issue tracker.

Standard Hints

Block variable aliases local variable - Unintentional side effect?

The block variable has the same name as a local variable, so it will reuse (and modify) the local variable which is sometimes not intended

  • Rename the block variable
  • Rename the local variable

Here's the editor showing a snippet which has a code fragment containing a block variable that has the same name as an outer local variable (and executing the block will modify the local variable):


The quick fix shows possible fixes:


Invoking one of the fixes initiates instant-rename on the relevant references (either the block references or the local variable references).


Rails Deprecations

Identifies deprecated Rails constructs; see


Here's another:


Code block on single line

Code blocks on a single line can optionally be reformatted to span multiple lines


  • Reformat code block to span multiple lines


After applying the above fix:


Additional Hints

The following hints were experimental in 6.0 (and not included in the base download, but available on the Update Center). In 6.1, these hints are all included as standard hints.

Nested local variable

Detects local variable usages that are "nested" (such as in for loops) where the loop variable is being reused

Offers the following fixes:

  • Rename the inner variable
  • Rename the outer variable




Convert between {}-blocks and do/end blocks

Convert between {}-blocks and do/end blocks


Applying fix shows this:


The code can also collapse multi-line blocks into a single line block, and vice versa. Here's a multi-line block:


Here's a single line block:



  • Convert {}-block to a do/end-block, and collapse to a single line
  • Convert {}-block to a do/end-block
  • Convert do/end-block to a {}-block, and collapse to a single line
  • Convert do/end-block to a {}-block
  • Expand single-line block to multiple lines
  • Collapse multi-line block to a single line

Uppercase constant name check

Check constant names to find CamelCase names rather than the preferred CONSTANT style


CamelCase name alert

Check method names to find camelCase names instead of the preferred method_name style


  • Rename to <name converted to underline-style>
  • Rename...


Check identifiers for unsafe characters

Only a-z, A-Z, digits and underscore are safe in identifier names. Other international character can lead to runtime errors.


Find actions without corresponding view files

Locates actions in Rails controller files that don't have a corresponding view file


  • Create view (open generator)


Local Attributes

Detects cases where a local variable assignment is referring to a local variable

whose name is identical to an attribute on this class, which is a common source of errors.


  • Change assignment to self.<name> to use attribute
  • Rename local variable to avoid confusion
  • Go to the relevant attribute definition (<attribute listed here>)

The following code sample shows the problem:


Here's the quick fix:


Error Fixes

In additional to flagging possibly bad code, hints can also be keyed off specific parser errors.

Incorrect =begin/=end blocks

Some users filed bugs that =begin/=end wasn't working correctly in NetBeans. The problem was however that they had indented their =begin/=end block, and in Ruby, it *must* appear in column 0. Thus, this hint describes the problem and offers to automatically fix it.

Here's the error - notice the lightbulb next to the error stop sign:


And here's the quickfix:


Parenthesize Arguments

Ruby warns when expressions with arguments really should have parentheses to avoid confusion (and the code may be disallowed in the future). NetBeans offers to fix these problems:


Extract Method

More information here.


Introduce Field, Introduce Constant, Introduce Variable


More information here.

Accidental Assignments

This tip detects mistakes like the following

x = 1
y = 2
puts "equal" if x = y

It also contains a quickfix to fix the problem (change it to x == y).

Experimental Hints

These hints are experimental in the sense that they were recently added. They are not part of the standard download; instead, they are included in the "Extra Hints" plugin, available from the update center. They are also included in the daily builds on

Reverse Conditional Logic

This quickfix checks if the caret is inside an if or unless statement, and if so, it offers to replace statements of this form:

if !x


unless x

and similarly,

if foo != bar


unless == bar

(The opposite scenario, converting unless !x to if x is also supported).

(You can see some screenshots of this in this blog entry)

Convert To Statement Modifier

This hint will convert if/unless statements of this form:

if foo


bar if foo

(You can see some screenshots of this in this blog entry)

RubyGem Deprecations

RubyGems 1.0 is out and has removed the old Kernel#require_gem method (which is used by older versions of Rails for example). The deprecation quickfix identifies these usages and offers to fix them.


Other Deprecations

NetBeans also checks for many other deprecated usages. Attempting to require getopts, parsearg, printenv or cgi-lib will generate warnings, as will the assert_raises method from Test::Unit (deprecated in Rails 1.9).

Retry Outside Rescue

It was just decided that "retry" must be inside a rescue statement in Ruby 1.9. This rule detects code where this is not the case, and warns about it such that you can update your code to work on Ruby 1.9.


Case/When Statements With Colons

As of Ruby 1.9, you cannot use colons to separate when statements. This quickfix detects this problem and offers to fix it.

More details in this blog entry


Hash List Conversion

As of Ruby 1.9, you can no longer write hashes like this:

{ "a", "b", "c", "d" }

You must instead use the following form:

{ "a" => "b", "c" => "d" }

This quickfix detects usages of the former construct and offers to convert it to the latter.


You can enable and disable hints in the options dialog:


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