Paul Krill
Editor at Large

Ruby steps toward frozen string literals

news
May 16, 20242 mins

Beginning with Ruby 3.4.0, string literals in files without a frozen_string_literal comment will behave as if they were frozen.

pile of poorly sorted red ruby crystals
Credit: Potapov Alexander / Shutterstock

The next version of the Ruby programming language, Ruby 3.4.0, has been released in preview, bringing changes for string literals and class updates.

Unveiled May 16, the Ruby 3.4.0 preview is downloadable from ruby-lang.org. With this update, string literals in files without a frozen_string_literal comment now behave as if they were frozen. If mutated, a deprecation warning is emitted. The change marks a first step toward making frozen string literals the default in Ruby. Frozen or immutable strings offer both performance and safety advantages.

In other language changes, keyword splatting nil when calling methods now is supported, while block passing and keyword arguments are no longer allowed in indexes.

Ruby 3.4.0 also introduces two core class updates. First, Exception#set_backtrace now accepts arrays of Thread::Backtrace::Location, and Kernel#raise, Thread#raise, and Fiber#raise accept this new format as well. Second, Range#size now raises TypeError if the range is not iterable.

Error messages and backtrace displays have been changed to address compatibility issues. Developers now can use a single quote instead of a backtick as an opening quote. It is also now allowed to display a class name before a method name when the class has a permanent name.

In other improvements, Array#each has been rewritten for better performance. Passing a block to a method that does not use the passed block now will show a warning in verbose mode. And redefining some core methods that are specially optimized by the interpreter and JIT now will emit a performance class warning.

Ruby 3.4.0 follows predecessors including last month’s Ruby 3.2.4 release, which brought security fixes, and the Christmas 2023 Ruby 3.3.0 release, which featured the Prism parser. Ruby itself dates back to a 1995 initial public release.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author