Should you upgrade to Ruby 3?

Mav Tipi
3 min readJan 7, 2021

Ruby is updated once a year, on Christmas. Two weeks ago, it got one of its most significant updates, going from version 2.7.2 to a big shiny 3.

What’s new in Ruby 3?

Here’s the official release announcement with details. I will attempt to summarize some new features.

• It’s faster

Increasing speed was one of the key goals behind 3.0., and by all accounts it went well. In fact, the stated goal was to make it “three times” faster than 2.0. A couple of caveats: 2.0 was quite a while ago, and there were a lot of performance gains between there and 2.7.2. And generalizing a language’s speed is very fuzzy. And with Ruby specifically, if you’re building a Rails app, it’s mostly dependant on Rails; it might be tough for you to realize Ruby’s performance gains until Rails adapts and updates in response.

One other speed improvement, aside from general performance, is that pasting Ruby code into an IRB is now much faster. If you’ve ever tried this, you know it takes forever — well, now it doesn’t.

• Ruby now has “endless” methods

Until now, Ruby was one of those languages where you have to write “end” to close a function. Now there’s a new single-line syntax that doesn’t require “end”s:

def cube(x) = x * x * x

I think that’s pretty neat and I’m excited to use it.

• Hashes have an “except” method

Hashes have a new method to return themselves minus a selection.

newHash = { name: 'Mavi', game: 'blogging', bubblegum: 0}
newHash.except(:bubblegum)
#=> {name: 'Mavi', game: 'blogging'}

• Many standard libraries have been updated

Last week’s article talked about one of these changes (DateTime in ‘date’ being depreciated). Well, there are lots.

• Concurrency

This is a big deal. Ruby has historically not had any native support for concurrency (i.e. doing several operations at once). This is one of the things that made it simple and easy to use, but it’s a real limiting factor. With 3.0, Ruby has two new features for concurrent programming (one small-scale and easily integrated, and one large-scale and still experimental.)

These are not all of the changes, just most of the mature ones. The official release announcement (here again) is a complete and in-depth expansion of this summary.

So should I update?

The point of a new big number is that it breaks stuff from previous releases. You probably don’t want to upgrade to Ruby 3 if you’re currently working on projects on older versions of Ruby and don’t have time to stop and fix things — especially if they have other dependencies.

And as touched on above, if you’re working exclusively in Rails, it’s probably best to wait until Rails has a new release that takes Ruby 3 into account.

If either of these reasons causes you to not want to update right now, it’s still probably a very good idea to update to 2.7.1. Nothing will break (probably), and you’ll get warnings for everything that’s due to break with 2.7.2/3.0.0.

You should update to 3.0.0 at the earliest time that neither of those apply to you. However there is one more thing to keep in mind — new big-number releases are very likely to get important x.0.1 patches. So far I haven’t been made aware of anything broken in 3.0.0, but it’s still prudent if you’re updating to keep your eyes peeled for 3.0.1 and hop on that as soon as possible.

Version Managers

One final note: In order to manage projects developed on different versions of Ruby, you’ll want a version manager to allow you to easily switch back and forth. I’ve used RVM; I’m also aware of chruby and rbenv that are frequently recommended and accomplish the same thing.

--

--