
Ruby 4.0.0 Released | Ruby
Ruby 4.0.0 Released 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 *nil no longer calls nil.to_a , similar to how **nil does not call nil.to_hash . [ Feature #21047 ] Logical binary operators ( || , && , and and or ) at the beginning of a line continue the previous line, like fluent dot. The following code examples are equal: if condition1 && condition2 ... end Previously: if condition1 && condition2 ... end if condition1 && condition2 ... end Core classes updates Note: We’re only listing outstanding class updates. Array Array#rfind has been added as a more efficient alternative to array.reverse_each.find...
Preview: ~500 words
Continue reading at Hacker News
Read Full Article