High level recap of new Ruby 3.2 features
Published on February 15, 2023 by Mike Chilson
Ruby Programming Versions
2 min READ
Recently, Ruby 3.2 was released with new features that improve the language’s capabilities and make it even more useful for developers. In this blog post, we’ll explore some of the most exciting features in Ruby 3.2.
Improved performance One of the most significant improvements in Ruby 3.2 is its enhanced performance. The new version includes an updated garbage collector that reduces memory usage and speeds up performance. This update has made Ruby 3.2 up to 30% faster than its predecessor, Ruby 3.1.
WASI based WebAssembly support This is an initial port of WASI based WebAssembly support. This enables a CRuby binary to be available on a Web browser, a Serverless Edge environment, or other kinds of WebAssembly/WASI embedders. Currently this port passes basic and bootstrap test suites not using the Thread API.
Pattern Matching Ruby 3.2 has added a new feature called pattern matching, which simplifies conditional statements and reduces the need for complex code. Pattern matching allows developers to match specific patterns in data structures and perform actions based on those patterns. This feature makes code easier to read and write and is a significant improvement over the previous case statement.
Production ready YJIT YJIT, the new JIT compiler for Ruby, was released last year as an experimental feature. Now it’s been marked production ready, and brings even more performance gains. YJIT was also completely rewritten in Rust in order to make it easier to maintain. This allowed the team to quickly add support for ARM. This means that you can now run YJIT on your M-series macs or a Raspberry Pi.
Backward Compatibility One of the essential features of Ruby is its backward compatibility. Developers who have built applications with older versions of Ruby can upgrade to the latest version without having to rewrite their code. Ruby 3.2 maintains backward compatibility while offering new features and improvements, making it easier for developers to keep their applications up-to-date.
Immutable Strings Ruby 3.2 introduces immutable strings, which cannot be changed once created. Immutable strings improve memory usage and performance by reducing the number of objects created during string operations. This feature also makes it easier to reason about the behavior of strings in Ruby programs.
Enumerable#compact The compact method is a familiar feature in Ruby, used to remove nil values from an array. Ruby 3.2 introduces a new method, Enumerable#compact, which allows developers to remove nil values from any enumerable object, not just an array. This addition makes code more versatile and readable.
Improved Regexp matching algorithm Since Ruby 3.2, Regexp’s matching algorithm has been greatly improved by using a memoization technique. The improved matching algorithm allows most Regexp matching (about 90% in our experiments) to be completed in linear time.
In conclusion, Ruby 3.2 includes several significant improvements that make it an even more powerful and efficient programming language. With its enhanced performance, new concurrency model, and other new features, Ruby 3.2 is an excellent upgrade for developers looking to improve the performance and maintainability of their applications. If you’re a Ruby developer, it’s worth upgrading to take advantage of the new features in Ruby 3.2. Also, these are by no means all the improvements in Ruby 3.2 To learn more please visit the release notes