def load_rails_gem
  if version = self.class.gem_version
    if version =~ /~>\s*((\d+\.){2})\d+/
      gem 'rails', version, "< #{$1}99"
    else
      gem 'rails', version
    end
  else
    gem 'rails'
  end
end

# now, specifying '~> 2.0.2' as RAILS_GEM_VERSION results in this call:
gem 'rails', '~> 2.0.2', '< 2.0.99'