Quickly Familiarise Yourself with the Interesting New Features in Ruby 3.0

Louise Swift
3 min readJul 7, 2021

If you are already familiar with concepts like concurrency and parallelism, static typing and type-checking, definitions and assignments, you may prefer to jump straight into experimenting with the new Ruby 3.0 features that we’re going to talk about here.

Otherwise, read on for a beginner-level overview of why these features may be significant for Ruby developers.

Note: These features are still experimental. Their continued inclusion in the Ruby language depends on ongoing discussions.

1. Concurrency and parallelism

There are various ways to make code run faster and more efficiently.

Two approaches are concurrency and parallelism:

Image source

Ruby has had fibers (code blocks that can be paused and resumed, enabling concurrency) since version 1.9, but 3.0 introduces Ractors for parallelism.

The best way to get used to working with asynchronous code is to experiment. This tutorial will walk you through fibers and Ractors with demonstrations of how they both work.

2. Rightward assignment

This one is quite simple, but that doesn’t mean it can’t upend your entire reality.

Personally, I needed some background for this one.

Which programming languages use rightward assignment? R is one, and so is COBOL.

Is rightward assignment easier for humans to reason about? Having scanned this entire StackOverflow thread, the only debate that interested me was regarding equality vs assignment in a mathematical sense (in an equality relation, the pair of entities in question can of course sit on either side of the equality symbol — but this is not the case with an assignment).

Do we need this for any reason? Hard to say. Convention is very helpful in programming. But if you’ve seen — or written — a rightward assignment that makes more sense than a leftward one, in any language, please do share.

3. Static types and type-checking

For many users of JavaScript, adding static types and type-checking via Typescript has improved our day-to-day work.

Yes, you can declare a variable and define a function (with particular expected arguments) in vanilla JavaScript.

But then, elsewhere in the codebase, someone (possibly your future self) can come along and invoke that function with any arguments they like.

If a function expects a number but receives an array that contains a number, then the function may struggle to output the desired result.

To remedy these sorts of issues, we can add Typescript to our JavaScript projects and start defining exactly what type of arguments a function should receive and return, or exactly what type of value a variable should hold.

Then we can compile the project and have Typescript warn us if we’ve provided any functions with the wrong number and/or type of arguments.

For the same reasons, Ruby language developers have been looking into static typing and type-checking options for some time. For example, engineers at Stripe developed the open-source Sorbet gem.

But now Ruby 3.0 includes a somewhat leaner implementation, using the Steep gem, that you can try by following these examples.

Bonus: Endless method definitions

This one’s just a simple but pleasing syntax option to have available.

Ready to experiment with these new features? As you’ll have seen from the links included above, the examples in this code repository are ready to help you quickly see how they work.

--

--

Louise Swift

Software engineer at FutureLearn. Mathematics BSc student.