Introduction
Ruby turned 30 in December 2025, and the core team marked it with Ruby 4.0, released on Christmas Day as usual. The big version number is partly a celebration—there is no wave of breaking syntax—but there is plenty under the hood: Ruby Box, a new JIT called ZJIT, a reworked Ractor API, and a long list of quality-of-life improvements. In this guide, the Asistensia team—Ruby on Rails consultants who upgrade production apps for a living—explains what is new in Ruby 4.0, what can break, and how to upgrade safely.
Ruby 4.0 at a Glance
- Released: December 25, 2025 (Ruby's 30th anniversary)
- Headline features: Ruby Box, ZJIT, Ractor::Port
- Built into core: Set and Pathname
- Bundled tooling: RubyGems and Bundler 4
- Official notes: Ruby 4.0.0 release announcement
Why Ruby 4.0 Matters
- Faster object creation and a leaner GC with no code changes
- New building blocks for isolation and parallelism (Ruby Box, Ractor::Port)
- Cleaner core APIs:
SetandPathnameare now built in - A handful of removals you should catch in CI before production does
1) Ruby Box: Isolated Definitions (Experimental)
Ruby Box isolates definitions from each other. Monkey patches, global and class variable changes, class and module definitions, and loaded libraries (Ruby or native) stay inside their own box. It is enabled with an environment variable and exposed as Ruby::Box.
RUBY_BOX=1 ruby app.rb
Where it could help:
- Running tests in isolation so monkey patches do not leak between them
- Running two versions of an app side by side in one process (blue/green style)
- Comparing responses before and after a dependency upgrade
It is experimental—great to explore, not something to depend on yet.
2) ZJIT: Ruby's Next-Generation JIT Compiler
ZJIT is a new method-based JIT compiler from the team behind YJIT. In 4.0 it is already faster than the interpreter but not yet as fast as YJIT, and the core team does not recommend it for production. The goal is for it to overtake YJIT and become production-ready in Ruby 4.1.
ruby --zjit app.rb # enable at startup
# or from Ruby code:
# RubyVM::ZJIT.enable
Building Ruby with ZJIT support requires Rust 1.85.0 or newer. For production today, stick with YJIT—which also gained mem_size: and call_threshold: options on RubyVM::YJIT.enable.
3) Ractor::Port: Easier Parallel Ruby
Ractors (Ruby's parallel actors) got a redesigned messaging model built on Ractor::Port:
port1 = Ractor::Port.new
port2 = Ractor::Port.new
Ractor.new port1, port2 do |port1, port2|
port1 << 1
port2 << 11
port1 << 2
port2 << 12
end
2.times { p port1.receive } #=> 1, 2
2.times { p port2.receive } #=> 11, 12
-
Added:
Ractor#join,Ractor#value(like Thread), andRactor.shareable_proc/Ractor.shareable_lambda -
Removed:
Ractor.yield,Ractor#take,Ractor#close_incoming,Ractor#close_outgoing - Lots of internal work on lock contention, plus deadlock and race fixes
The core team aims to drop the "experimental" label soon. If you experimented with the old API, expect to rewrite that code.
4) New Syntax in Ruby 4.0
Lines can now start with a logical operator (&&, ||, and, or) and continue the previous line—just like leading-dot method chains:
if user.active?
&& user.verified?
&& !user.banned?
grant_access
end
And *nil no longer calls nil.to_a, matching how **nil already behaves—optional splats are now cheap and clean:
tags = ["news", *optional_tags, "ruby"] # optional_tags can be nil
5) Core Class Updates: Set, Pathname, Array#rfind
-
Set is core: no more
require "set";inspectnow printsSet[1, 2, 3] - Pathname is core: promoted from a default gem
-
Array#rfind: a faster alternative to
reverse_each.find -
Kernel#inspect: define a private
instance_variables_to_inspectto hide noisy (or sensitive) ivars -
Enumerator.produce accepts a
size:keyword - String#strip and friends accept character selectors; Unicode/Emoji updated to 17.0
- Math.log1p and Math.expm1 added
-
Socket.tcp / TCPSocket.new accept
open_timeout: -
ErrorHighlight shows both the call site and the method definition for
ArgumentError
class Connection
def initialize(host, user, password)
@host, @user, @password = host, user, password
end
private def instance_variables_to_inspect = [:@host, :@user]
end
Connection.new("db.local", "app", "s3cret").inspect
# => #<Connection:0x... @host="db.local", @user="app">
6) Ruby 4.0 Performance Improvements
-
Class#newis faster, especially with keyword arguments—great news for object-heavy Rails apps - GC heaps grow independently per size pool, reducing memory use; faster sweeping for large objects
- Faster instance variable access on Strings, Arrays and other "generic ivar" objects
- Faster
object_idandhashon classes and modules
7) Breaking Changes: What Can Break When Upgrading
-
Gems moved to bundled:
ostruct,pstore,benchmark,logger,rdoc,irb,reline,readline,fiddle,win32ole—add them to your Gemfile if you use them under Bundler -
CGI removed from default gems (except
cgi/escape); SortedSet now needs thesorted_setgem -
Net::HTTP no longer adds
Content-Type: application/x-www-form-urlencodedautomatically—set it explicitly where needed -
Kernel#open/IOno longer spawn processes from a leading| -
ObjectSpace._id2refdeprecated;--rjitremoved - RubyGems and Bundler are now version 4
Ruby 4.0 Upgrade Checklist
- Run the test suite on Ruby 4.0 in CI with deprecation warnings on
- Add newly bundled gems (logger, ostruct, benchmark…) to the Gemfile
- Grep for
SortedSet,require "cgi",Ractor.yield, andopen("|...") - Check outbound
Net::HTTPPOSTs for an explicitContent-Type - Update Docker base images and Bundler 4 lockfiles
- Keep YJIT on in production; try ZJIT in staging out of curiosity
How Asistensia Helps You Upgrade to Ruby 4.0
Asistensia is a software consulting company specialising in Ruby on Rails, PHP/Laravel and DevOps. We take Ruby and Rails apps to the latest versions in small, reversible steps—without feature freezes or downtime.
- Upgrade audit: gem compatibility, deprecations and a risk-ranked plan
- Hands-on upgrades: Ruby 3.x → 4.0 and Rails 7 → 8, with CI and Docker images updated
- Performance tuning: YJIT, GC and memory settings tuned for your workload (see our Rails performance audit)
- Ongoing support: Ruby on Rails consulting and DevOps consulting for teams that need senior help
Book a free 30-minute consultation with Asistensia, or email contact@asistensia.com.
Ruby 4.0 FAQ
When was Ruby 4.0 released?
Ruby 4.0.0 was released on December 25, 2025, shortly after Ruby's 30th anniversary. Patch releases (4.0.x) follow roughly every two months.
Is Ruby 4.0 backward compatible with Ruby 3.4?
Mostly, yes. Most apps only need Gemfile updates for gems that moved out of the default set (such as logger, ostruct and benchmark). Code using the old Ractor API, SortedSet, CGI or pipe-based Kernel#open needs changes.
Should I use ZJIT or YJIT in production?
Use YJIT. ZJIT is experimental in Ruby 4.0 and not yet as fast as YJIT; the core team aims to make it production-ready in Ruby 4.1.
Does Rails 8 work with Ruby 4.0?
Yes—use the latest Rails 8.1 patch release, which includes fixes for Ruby 4.0 warnings, and check that your other gems support Ruby 4.0. Upgrade Ruby first, then Rails, as described in our Rails 8 upgrade guide.
Can Asistensia upgrade my app to Ruby 4.0?
Yes. Asistensia offers Ruby and Rails upgrade audits and hands-on upgrades for teams worldwide. Get in touch to plan yours.
Conclusion
Ruby 4.0 is less about new syntax and more about laying foundations for the next decade: isolation with Ruby Box, a new JIT with ZJIT, and a Ractor API that is finally settling down. For most apps, the upgrade is a matter of tidying the Gemfile and picking up free performance. Planning a move to Ruby 4.0 or Rails 8? See our Rails 8 upgrade guide—or contact Asistensia and we will help you ship it safely.
Written by Ahmad
Ahmad Hassan, founder of Asistensia and Senior Ruby on Rails expert with 10+ years of experience. He builds web and mobile applications using React, Next.js, and TypeScript, and contributes to backend development using Python and Ruby on Rails.
Originally published on the Asistensia blog. Asistensia is a software consultancy for Ruby on Rails, PHP/Laravel and DevOps. Book a free 30-minute consultation.
Top comments (0)