🚀 Discover this trending post from Hacker News 📖
📂 Category:
💡 Here’s what you’ll learn:
Posted by naruse on 25 Dec 2025
We are pleased to announce the release of Ruby 4.0.0.
Ruby 4.0 introduces “Ruby Box” and “ZJIT”, and adds many improvements.
Ruby Box
Ruby Box is a new (experimental) feature to provide separation about definitions. Ruby Box is enabled when an environment variable RUBY_BOX=1 is specified. The class is Ruby::Box.
Definitions loaded in a box are isolated in the box. Ruby Box can isolate/separate monkey patches, changes of global/class variables, class/module definitions, and loaded native/ruby libraries from other boxes.
Expected use cases are:
- Run test cases in box to protect other tests when the test case uses monkey patches to override something
- Run web app boxes in parallel to execute blue-green deployment on an app server in a Ruby process
- Run web app boxes in parallel to evaluate dependency updates for a certain period of time by checking response diff using Ruby code
- Used as the foundation (low-level) API to implement kind of “package” (high-level) API (it is not designed yet)
For the detail of “Ruby Box”, see Ruby::Box.
[Feature #21311] [Misc #21385]
ZJIT
ZJIT is a new just-in-time (JIT) compiler, which is developed as the next generation of YJIT. You need Rust 1.85.0 or newer to build Ruby with ZJIT support, and ZJIT is enabled when --zjit is specified.
We’re building a new compiler for Ruby because we want to both raise the performance ceiling (bigger compilation unit size and SSA IR) and encourage more outside contribution (by becoming a more traditional method compiler). See our blog post for more details.
ZJIT is faster than the interpreter, but not yet as fast as YJIT. We encourage you to experiment with ZJIT, but maybe hold off on deploying it in production for now. Stay tuned for Ruby 4.1 ZJIT.
Ractor Improvements
Ractor, Ruby’s parallel execution mechanism, has received several improvements. A new class, Ractor::Port, was introduced to address issues related to message sending and receiving (see our blog post). Additionally, Ractor.shareable_proc makes it easier to share Proc objects between Ractors.
On the performance side, many internal data structures have been improved to significantly reduce contention on a global lock, unlocking better parallelism. Ractors also now share less internal data, resulting in less CPU cache contention when running in parallel.
Ractor was first introduced in Ruby 3.0 as an experimental feature. We aim to remove its “experimental” status next year.
Language changes
-
*nilno longer callsnil.to_a, similar to how**nildoes
not callnil.to_hash. [Feature #21047] -
Logical binary operators (
||,&&,andandor) at the
beginning of a line continue the previous line, like fluent dot.
The following code examples are equal:if condition1 && condition2 ... endPreviously:
if condition1 && condition2 ... endif condition1 && condition2 ... end[Feature #20925]
Core classes updates
Note: We’re only listing outstanding class updates.
-
Array
Array#rfindhas been added as a more efficient alternative toarray.reverse_each.find[Feature #21678]Array#findhas been added as a more efficient override ofEnumerable#find[Feature #21678]
-
Binding
-
Binding#local_variablesdoes no longer include numbered parameters.
Also,Binding#local_variable_get,Binding#local_variable_set, and
Binding#local_variable_defined?reject to handle numbered parameters.
[Bug #21049] -
Binding#implicit_parameters,Binding#implicit_parameter_get, and
Binding#implicit_parameter_defined?have been added to access
numbered parameters and “it” parameter. [Bug #21049]
-
-
Enumerator
-
Enumerator.producenow accepts an optionalsizekeyword argument
to specify the size of the enumerator. It can be an integer,
Float::INFINITY, a callable object (such as a lambda), ornilto
indicate unknown size. When not specified, the size defaults to
Float::INFINITY.# Infinite enumerator enum = Enumerator.produce(1, size: Float::INFINITY, &:succ) enum.size # => Float::INFINITY # Finite enumerator with known/computable size abs_dir = File.expand_path("./baz") # => "/foo/bar/baz" traverser = Enumerator.produce(abs_dir, size: -> 🔥) Share your opinion below! traverser.size # => 4[Feature #21701]
-
-
ErrorHighlight
-
When an ArgumentError is raised, it now displays code snippets for
both the method call (caller) and the method definition (callee).
[Feature #21543]test.rb:1:in 'Object#add': wrong number of arguments (given 1, expected 2) (ArgumentError) caller: test.rb:3 | add(1) ^^^ callee: test.rb:1 | def add(x, y) = x + y ^^^ from test.rb:3:in ''
-
-
Fiber
- Introduce support for
Fiber#raise(cause:)argument similar to
Kernel#raise. [Feature #21360]
- Introduce support for
-
Fiber::Scheduler
-
Introduce
Fiber::Scheduler#fiber_interruptto interrupt a fiber with a
given exception. The initial use case is to interrupt a fiber that is
waiting on a blocking IO operation when the IO operation is closed.
[Feature #21166] -
Introduce
Fiber::Scheduler#yieldto allow the fiber scheduler to
continue processing when signal exceptions are disabled.
[Bug #21633] -
Reintroduce the
Fiber::Scheduler#io_closehook for asynchronousIO#close. -
Invoke
Fiber::Scheduler#io_writewhen flushing the IO write buffer.
[Bug #21789]
-
-
File
File::Stat#birthtimeis now available on Linux via the statx
system call when supported by the kernel and filesystem.
[Feature #21205]
-
IO
-
IO.selectacceptsFloat::INFINITYas a timeout argument.
[Feature #20610] -
A deprecated behavior, process creation by
IOclass methods
with a leading|, was removed. [Feature #19630]
-
-
Kernel
-
Kernel#inspectnow checks for the existence of a#instance_variables_to_inspectmethod,
allowing control over which instance variables are displayed in the#inspectstring:class DatabaseConfig def initialize(host, user, password) @host = host @user = user @password = password end private def instance_variables_to_inspect = [:@host, :@user] end conf = DatabaseConfig.new("localhost", "root", "hunter2") conf.inspect #=> #<0x0000000104def350/>
-
⚡ Tell us your thoughts in comments!
#️⃣ #Ruby #4.0.0 #Released #Ruby
🕒 Posted on 1766641805
