Should you upgrade to Ruby 3?

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.

• 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

• Hashes have an “except” method

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

newHash = { name: 'Mavi', game: 'blogging', bubblegum: 0}
#=> {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.)

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.

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.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store