Ruby Screenshot of the Week #25: require_gem

There have been a number of releases lately. Rails 2.0 shipped. NetBeans 6.0 mostly supports it. There were a couple of changes, such as the scaffold generator's parameters changing meaning, and the new shorthand migration syntax, which affected NetBeans. I've committed changes to 6.1 to support these, so grab the latest if you're wanting complete Rails 2.0 support. However, note that we're in early 6.1 development so there's some big potentially destabilizing changes, such as a new platform manager which lets you choose per project ruby interpreters, configure separate gem repositories and so on. I'll post more about this when it's done. You don't need to upgrade if you're just wanting to use Rails 2.0 - nearly everything in NetBeans 6.0 works just fine.

JRuby 1.0.3 also recently
shipped, and I've just updated NetBeans 6.1 to use it. JRuby 1.0.3 lets you run Rails 2.0 without needing to install the optional jruby-openssl gem.

I just noticed that RubyGems 1.0 has
shipped. One of the changes in RubyGems is that the require_gem method, which has been deprecated for a while, is now gone - so you have to update your code appropriately. require_gem was used by previous versions of Rails, so many boot.rb files still reference it.

I just added a checker for this:

It's not just a warning - it's a quickfix:

The "Show More information" fix opens the browser on the release page for RubyGems 1.0 which briefly mentions the require_gem removal. If anyone has a better URL to an official and mostly permanent page (e.g. preferably not somebody's blog) discussing this change, I'd appreciate the link.

Ruby 1.9 is getting closer. Charlie recently
pointed out to me that they recently
decided that retry statements will as of Ruby 1.9 only be allowed inside
rescue blocks. Thus, we now have a hint to look for problems of this sort.

If anyone has
any ideas for other Ruby 1.9 migration issues, please
let us know!

Finally, let me end with a couple of links. The "Off The Line" blog has posted
cheatsheets for the NetBeans Ruby support, PDFs that summarize key shortcuts and other hints. And Michael Slater, one of the early adopters of the NetBeans Ruby support, will be offering a Rails Seminar in a couple of months, which is going to be using NetBeans. W00t!

Updated a few hours later: Dr. Nic pointed out that require_gem can't
just be replaced by gem and showed me how the code needs to be morphed. I've updated the
quickfix to do The Right Thing now - thanks Dr. Nic!


@Tor, you might need to replace 'require_gem' with either just 'require' or a combo of 'gem' + 'require'. The gem statement doesn't load the library, just adds it to the $LOAD_PATH, I think

Posted by Dr Nic on December 20, 2007 at 05:10 AM PST #

Thanks Dr. Nic! I wish this would be clearer in the docs; the command just emits the message "Warning: require_gem is obsolete. Use gem instead." and I've done some googling to see what the correct replacement is, but it's still not clear to me. Is it correct that to replace something like

require_gem "rails"

I would replace it with

require "rubygems" (if not already required)
require "rails"

and to replace something like this:

require_gem "rails", "2.0.1"

I would need to do replace it with

require "rubygems" (if not already required)
gem "rails", "2.0.1"

Does this second form also need a require "rails", and if so, before or after the gem command?

Thanks for pointing this out to me!

Posted by Tor Norbye on December 20, 2007 at 06:08 AM PST #

You won't need to auto-generate require "rubygems" as it is assumed the refactored code has already included this, else require_gem wouldn't be available (Kernal#require_gem was a rubygems construct).


require_gem 'rails'


gem 'rails'
require 'rails'


require_gem 'rails', '2.0.1'


gem 'rails', '2.0.1' (or '=2.0.1', not sure, I don't use this one much)
require 'rails'


Posted by Dr Nic on December 20, 2007 at 06:22 AM PST #

Thanks! I've updated the quickfix code - and the above blog entry :)

Posted by Tor Norbye on December 20, 2007 at 07:21 AM PST #

Tor, we can't thank you and your team enough for the fantastic work you've done with Netbeans 6. We've been using it since the summer and we built the new with it. It's a fantastic IDE, and by far the best environment for Rails development -- the bonus is that it's cross platform. Cheers!

Posted by Brian Ketelsen on December 20, 2007 at 08:40 AM PST #

Thanks a lot Brian!

Posted by Tor Norbye on December 20, 2007 at 08:45 AM PST #

Hi, Tor!! Some bugs: HAML module doesn't work in last versions, also debuger sometime doesn't work in views (particularly inside partials - breakpoints just do nothing). Also I haven't found options for fast-debug - is it working automatically, when select native ruby for the project?
About different color scheme - I've found, that there were some changes of names in the xml config files, so that it's why last versions don't support my color scheme (in Ruby files)

Posted by ruby.freeman on December 20, 2007 at 03:28 PM PST #

Hi Tor,
here's an amazing list of Ruby 1.9 changes.

The URL seems to be offline at the moment,
but it's available in Google cache.

Posted by Simone Carletti on December 21, 2007 at 12:27 AM PST #


The IDE is absolutely great!
But there appears to be a bug in the indexing of the Ruby 1.0.3 library. On each startup the IDE spends about 15 min indexing jruby-1.0.3\\lib\\ruby\\1.8

Best regards,
Ajasja Ljubetič

Posted by Ajasja Ljubetič on December 25, 2007 at 08:26 PM PST #

Good day, Tor! Another little bug - keymap for "Go to declaration" desn't work - it works only from context menu. Thanks for your work!!

Posted by ruby.freeman on December 26, 2007 at 07:42 AM PST #

Happy New Year, Tor!! Best wishes to you!!

Posted by ruby.freeman on December 30, 2007 at 03:42 PM PST #

hi Tor, I updated to rails 2.0, i generated a proyect from the IDE (netbeans 6.0) but can´t see the rake tasks when I right click on the project. but rake works fine from the console. any hints?

Posted by gustavo on January 01, 2008 at 10:22 PM PST #

Post a Comment:
Comments are closed for this entry.

Tor Norbye


« July 2016