Ruby Screenshot of the Week #15: More Hints and Quick Fixes!

Ola Bini just posted a blog entry entitled "Ruby Is Hard". In the blog entry he shows a short code snippet which does not do what you might think upon reading it. This immediately reminded me of a dog-eared page in my worn-out copy of "Programming Ruby", specifically page 167, in the "But It Doesn't Work" section. The book covers the same problem and explains what the problem is and how to fix it.

I had marked the page for myself because when I first read it, I thought "that's something the IDE should be able to detect and warn you about!". So when I came across Ola's blog entry yesterday I figured I really should do something about it - and I had the perfect opportunity: A Java Posse recording session at Dick's new house last night. I've claimed before that writing quick fixes for Ruby in NetBeans is easy, and it really is - I completed this one as a background activity while having fun with the rest of the Posse. We are however past feature freeze for NetBeans 6, so when I'm adding fun features like this I put it into the "Experimental Hints" module, which is not part of NetBeans 6. It -is- however included in the continuous "Ruby IDE" builds you can get here - and you can also install it using the Plugin Manager in standard NetBeans.

So without further ado, here's what you get when you now open up Ola's example and the "Programming Ruby" example in NetBeans with the new hints:

As you can see, it's detecting the case there are local variable name assignments that match a writable attribute in the current class. If you hover over the warning it will tell you so:

If you hit Alt-Enter, you can see the possible fixes:

These should be pretty self-explanatory. At first you may go "Huh?" and jumping to the relevant attribute may help you figure it out. The second fix will simply change the assignment to the recommended form, and the third fix will let you rename the local variable to avoid any confusion.

In order to avoid any false positives I ran this hint over a large code base (all the Ruby libraries and Rails libraries) and it came up with a handful of warnings. These probably aren't bugs, but it's at least potentially confusing; here's baseData.rb from Ruby's SOAP library:

There are some other experimental hints too, in particular, a hint which detects actions in your controllers that don't have associated view files and offers to create them (using the Rails code generator), as well as various name warnings. Here's a warning which detects un-Ruby-like method names and local variable names (camelCase instead of not_camel_case) - this one from a Rails test case:

Here's the current customizer. Some of the hints are not enabled by default, so you should inspect these yourself and enable those you are interested in. One hint I definitely didn't want to enable by default is the "constant name" warning. I was under the impression that constants should use all upper-case letters separated by underscores, and this is indeed the case in lots and lots of Ruby code. But there are quite a few exceptions, where constants are just capitalized - so this seems like a warning that may need some tweaking or is an individual preference. Here's the customizer:

In other news, a lot of bug fixing is happening so stay up to date with the builds :)


Hi Tor! Nice work, as usual.. May be the support of HAML is also coming soon? ;) (sorry for the annoing, but much of us miss it very much)

Posted by freeman on August 09, 2007 at 02:59 PM PDT #

mmmh... what did I do wrong? I downloaded Netbeans M10 and I don't see this Ruby section in my options, only a Java section. Is it because I missed something in the installation or because of M10? I can still edit and run my test rails application, though.

Posted by Frederic D. on August 09, 2007 at 07:49 PM PDT #

As far as I know, anything with an initial caps is a constant (that's just the way Ruby is), but idiomatically constants other than class names are usually UNDERSCORED_ALL_CAPS. That's been my experience, anyway.

Posted by Shadowfiend on August 10, 2007 at 12:15 AM PDT #

[Trackback] 廢話不多說,有圖有真相! 今天看到一篇文章在介紹 Netbeans 對 Ruby 的支援,該篇文章主要是在介紹關於 Hints 的部份,也就是當你在寫 Ruby code 的時候,Netbeans 會檢查你的語法是否有問題(大...

Posted by ericsk's blog on August 10, 2007 at 12:25 AM PDT #

Hi Freeman,
sorry - I haven't done anything about HAML yet :(

Frederic, this is not in M10; you need the daily builds, such as the Ruby-only IDE available from

See for details. The Ruby wiki at has a lot of other useful information, such as the shortcuts document.

Shadowfiend, yes, that's my impression too - so what the hint does is check constants other than classnames to make sure they are UNDERSCORED_ALL_CAPS - but I came across quite a few files in the Ruby libraries where non-class constants were mix-cased. That's why I'm thinking this is a rule that people can turn on if they want to follow this convention but for the IDE to complain about it by default might be too much.

Posted by Tor Norbye on August 10, 2007 at 01:12 AM PDT #

If you integrate autotest (and failure notifications) then it'll ROCK and I'd ditch Textmate. :-)

Posted by Vishnu Gopal on August 10, 2007 at 02:45 AM PDT #

Wow Tor, that's great work. The only real desire left for me is to have a more mac like experience in the editor (ie, feel more like a cocoa app a la textmate) and to have a more refined dark theme shipped with it.

Some of these "minor" tweaks would really go a long way. But hey, you're work is outstanding; I just wish the other folks in the NB project would get on the ball like you.

I can't wait to see more of these subtle yet powerful enhancements from you that make our lives more complete.

Posted by John on August 11, 2007 at 03:54 AM PDT #

Tor -- interesting. Wonder why that is. Awesome work, either way :) If you ever do get around to adding HAML support, that will be so awesome it's not even funny. In the meantime, little enough needs to go on in HAML that I'm okay still using vim to do those files :)

Vishnu -- while failure notifications aren't integrated as far as I can see (some autotest screenshots showed them there, but I haven't seen them -- possibly because I'm using the jVi plugin and it takes control of the status bar?), autotest support is definitely there. Plus you can hook up autotest to a platform-specific notifier if you want (like KNotify in KDE).

Posted by Shadowfiend on August 12, 2007 at 11:37 AM PDT #

Thanks Tor,

I now downloaded the Ruby-only IDE and I love it! (I was still using Radrails :) ). It must be pretty enjoyable to produce such a fine tool.

Posted by Frederic D. on August 12, 2007 at 04:38 PM PDT #

Yeah, HAML would be very nice addition.

By the way, Tor, did you had a chance to think on remote scp/sftp file system?
I miss it very much, so it don't giving me a full pleasure of using RubyBeans every day due my remote access to the computers I work with.

Posted by Sergey Kuznetsov on August 15, 2007 at 02:59 AM PDT #

Hey Tor,

Thanks for all the great work. Writing in ruby is much more fun now :)

Just a quick heads up, there's two ruby screenshot of the week #15.

Posted by Albert Ng on August 15, 2007 at 09:48 AM PDT #


Tor, are the Ruby updates being pushed to the Daily Update Center at all? I installed M10 about a month ago, pointed the Plugins/Updates to the Daily Update Center as per the wiki, and haven't had a single Ruby update since. I've been downloading the nightlies and installing, but I was wondering if anything will come via the Update Center?

Posted by zerohalo on August 15, 2007 at 01:25 PM PDT #

Hi Tor,

Thanks for your effort on supporting Ruby and Rails in NetBeans. Do you have also plans to support HAML and SASS (

Eclipse now has support for HAML but I prefere NetBeans much more...

Posted by Petr Murmak on August 16, 2007 at 02:13 AM PDT #

hi Tor! Another thing, that i think would be very useful in NetBeans is (soft) word wrapping, or may be it is already implemented and I just don't know where it is?

Posted by freeman on August 23, 2007 at 01:54 PM PDT #

Hi all,
thank you for your comments! Sorry about the delay - I've been on vacation and then trying to catch up..
Freeman, yes soft word wrapping is implemented for comments and documentation (=begin/=end) sections. This is in recent builds. Go to the Formatting options for Ruby to enable it. You can also lazily just reflow the current comment paragraph - ctrl-shift-p / command-shift-p (I just added this keybinding yesterday so get a brand spanking new build to use it). Comment reflowing should know about all the rdoc conventions - lists, preformatted text etc. so if you find bugs, let me know.
Petr, I've received several requests for HAML but I won't get to it for NetBeans 6.0. Somebody (Marcin) expressed interest in helping out on it so perhaps we can get some preliminary support soon? If anybody else would like to help out, take a look at "languages/haml" in CVS. I just made goto action/view work for HAML.
Zerohalo, sorry, I'm not pushing updates to the M10 update center; during the rapid milestone cycle there's no simple automated way for me to push updates so to get the very latest, you unfortunately need to download whole kits. Luckily they're not giant (about 20 mb) and it solves one important problem: with auto update I need to be dilligent in marking version dependencies among modules, and if I make a mistake, you could run into bugs where you have incompatible versions of modules. With an IDE download you always have a consistent set of stuff. But once we get closer to release we'll start relying more heavily on auto update. (There is an automatic daily update center you can use if you have limited bandwidth, but you must use a daily build, not M10, to access it, or configure it by hand.)
Sergey, sorry, I haven't had a chance to work on support for remote filesystems. Hopefully for 6.1 :)

Posted by Tor Norbye on August 24, 2007 at 03:18 AM PDT #


Thanks a lot! I am eagerly waiting for that.

Posted by Sergey Kuznetsov on August 24, 2007 at 04:40 AM PDT #

Hi, Tor!! I meant the soft word wrapping for ruby code - the best way how it is done I've seen in Jedit - very often we have the lines that are bigger than screen - of course, we can divide them, but soft word wrapping would be very useful

Posted by freeman on August 24, 2007 at 11:57 AM PDT #

Post a Comment:
Comments are closed for this entry.

Tor Norbye


« July 2016