- Ruby 3.4 was released on December 25, 2024.
Language changes:
- Frozen string literals: By default, strings act as if frozen. Modifying a frozen string in a file with the magic comment will result in a deprecation warning instead of an error. A future version will raise an exception.
- Default block parameter: Ruby 3.4 introduces a default block parameter to make short code blocks cleaner. Instead of using numbered parameters or naming them, you can use a simple name like
it
. - Keyword splatting
nil
: In Ruby 3.4,**
withnil
implicitly convertsnil
into a hash.
Core classes updates:
- Exception#set_backtrace: In Ruby 3.4,
Exception#set_backtrace
accepts aThread::Backtrace::Location
array to rebuild aBacktrace
instance. - Range#size: If the range is not iterable, Ruby 3.4 will throw a
TypeError
when callingsize
.
- Exception#set_backtrace: In Ruby 3.4,
Other changes:
- Methods passing unused blocks: In verbose mode, Ruby will throw a warning if a block is passed to a method that doesn't use it.
- Array.each performance improvement: Ruby 3.4 improves the performance of
Array.each
due to an implementation rewrite. - Error message and backtrace display update: Ruby will use single quotes instead of backticks and display a class name before a method name.
- Upgrading to Ruby 3.4: Removing unneeded frozen string magic comments is the most labor-intensive part. Upgrading takes advantage of new features.
- More articles: There are various articles related to Ruby, including managing PostgreSQL table partitioning, Rails and No PaaS, Ruby regex tricks, using Pry to debug, UUIDs and ULIDs, Rails load testing in Apache JMeter, using Solid Cache, comparing Go vs Ruby, Rails async queries, and Honeybadger's migration from Sidekiq to Karafka.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。