Skip to content

Ruby 4.1 support #9746

Open
Open

Description

@headius

This feature checklist is based on the NEWS file from CRuby's master branch. We'll update this list until the release has been finalized.

Pull requests to implement Ruby 4.1 features should be based on the ruby-4.1 branch, not master.

Changes not relevant to JRuby have been removed.


NEWS for Ruby 4.1.0

This document is a list of user-visible feature changes
since the 4.0.0 release, except for bug fixes.

Note that each entry is kept to a minimum, see links for details.

Language changes

  • Module#clone and Module#dup no longer rewrite the lexical scope of
    copied methods. Constants and class variables resolve through the
    original class, consistent with inheritance and mixins.
    [Feature #21981]

  • alias and Module#alias_method in a module emit a deprecation warning
    when the original method is not a method of the module or its ancestors
    and is only found through the fallback to Object. The fallback will be
    removed in Ruby 4.3, and such an alias will raise a NameError.
    [Bug #22276]

  • alias and Module#alias_method emit a deprecation warning when the
    original method is defined in a prepended module. This behavior will
    be removed in Ruby 4.3, and alias lookup will start at the origin
    class (after prepended modules).
    [Bug #22273]

Core classes updates

Note: We're only listing outstanding class updates.

  • Array

    • Array#pack accepts new formats R and r for unsigned and signed
      LEB128 encoded integers. [Feature #21785]
    • Array#pack accepts new formats x! and @! to align the current
      offset to a byte boundary or to the ABI alignment of another
      directive. [Feature #22185]
  • Dir

    • Dir.glob supports ***/ for recursive matching that follows
      directory symbolic links, stopping at links to ancestor directories.
      [Feature #17548]
  • ENV

    • ENV.fetch_values is added. It returns an array of values for the
      given names, raising KeyError for missing names unless a block is
      given. [Feature #21781]
  • Fiber::Scheduler

    • The fiber_interrupt hook is now required. Schedulers which do not
      implement it can no longer be installed with Fiber.set_scheduler.
  • GC

    • GC.stat accepts scope: :ractor (the default), scope: :local
      (a synonym for :ractor), and scope: :global.
      With the default collector, the global scope reports cumulative collection
      counts and measured marking/sweeping CPU time across Ractors, including
      history from destroyed object spaces, without requesting a stop-the-world
      snapshot. Unscoped GC.stat, GC.count, and GC.total_time retain their
      current-Ractor behavior.
  • Hash

    • Hash.ruby2_keywords_hash? and Hash.ruby2_keywords_hash are
      deprecated and will be removed in Ruby 4.5. [Feature #22205]
  • Integer

    • Integer#bit_count is added. It returns the number of 1 bits in the
      binary representation of a non-negative integer (its population count).
      [Feature #20163]
  • IO::Buffer

    • [ ]read, write, pread, and pwrite now perform one IO operation using
      (offset, length), where length is the maximum transfer size. Short
      transfers are returned directly.

    • The corresponding fiber scheduler hooks are no longer experimental and
      now use the same (offset, length) argument order and single-operation
      semantics.

  • Kernel

    • Kernel#autoload_relative and Module#autoload_relative are added.
      These methods work like autoload, but resolve the file path relative
      to the file where the method is called, similar to require_relative.
      This makes it easier to autoload constants from files in the same
      directory without hardcoding absolute paths or manipulating $LOAD_PATH.
      [Feature #15330]
  • MatchData

    • [ ]MatchData#integer_at is added. It converts the matched substring to
      integer and return the result. [Feature #21932]
  • Module

    • Module#descendants is added. It returns an array of classes and
      modules that have the receiver in their ancestors. [Feature #9779]
    • Module#ruby2_keywords and top-level ruby2_keywords are
      deprecated and will be removed in Ruby 4.4. [Feature #22205]
    • [ ]Module#method_defined? now accepts a third optional argument to also
      match private methods. [Feature #22297]
  • ObjectSpace

  • Proc

    • Proc#refined is added. It returns a new Proc that behaves like the
      receiver but with the refinements activated by the given modules
      in effect inside its body, without affecting the original Proc.
      [Feature #22097]
    • Proc#ruby2_keywords is deprecated and will be removed in Ruby 4.4.
      [Feature #22205]
  • Range

    • Range#clamp is added. It returns a new Range instance whose
      begin and end values are clamped to the given bounds. [Feature #22175]
  • Regexp

    • All instances of Regexp are now frozen, not just literals.
      Subclasses of Regexp are not frozen for compatibility.
      [Feature #8948]
  • Set

    • A deprecated behavior, Set#to_set, Range#to_set, and
      Enumerable#to_set accepting arguments, was removed. [Feature #21390]
  • String

    • String#unpack and String#unpack1 accept new formats R and r
      for unsigned and signed LEB128 encoded integers. [Feature #21785]
    • String#unpack and String#unpack1 accept a new format ^ that
      returns the current offset. Useful when combined with variable
      width formats like LEB128. [Feature #21796]
    • String#unpack and String#unpack1 accept new formats x! and
      @! to align the current offset to a byte boundary or to the ABI
      alignment of another directive. [Feature #22185]
    • Basic bit operations are added. String#bit_get, String#bit_set?,
      String#bit_set, String#bit_clear, String#bit_flip and
      String#bit_count handle individual bits, and String#bitwise_not,
      String#bitwise_and, String#bitwise_or, String#bitwise_xor
      (with their ! variants) handle whole strings. [Feature #22118]
    • [ ]String#tr now accept a Hash for multi-character replacement.
      [Feature #22238]
  • Symbol

  • Thread

    • [ ]Assigning nil with Thread#thread_variable_set now deletes the
      thread-local variable. [[Feature #19333]]
  • Thread::Backtrace::Location

    • Thread::Backtrace::Location#source_range is added. It returns a
      Ruby::SourceRange for the Ruby expression associated with the frame.

Stdlib updates

  • Psych

    • An experimental libfyaml backend has been added. It is only
      enabled when psych is built with --enable-libfyaml, and the
      default libyaml backend remains unchanged otherwise. It is not
      supported on Windows. [GH-psych #805] (JRuby should confirm compatibility with SnakeYAML-Engine)

The following bundled gems are added.

We only list stdlib changes that are notable feature changes.

Other changes are listed in the following sections. We also listed release
history from the previous bundled version that is Ruby 3.4.0 if it has GitHub
releases.

The following bundled gems are promoted from default gems.

  • tsort 0.2.0
  • win32-registry 0.1.2

The following bundled gems are removed.

  • net-ftp 0.3.9
  • net-pop 0.1.2

They are still available on rubygems.org and can be installed with
gem install. [Feature #21835]

The following default gem is added.

The following default gems are updated.

The following bundled gems are updated.

RubyGems and Bundler

Ruby 4.0 bundled RubyGems and Bundler version 4. see the following links for details.

Compatibility issues

  • A class or module can now be modified only by the Ractor which created it,
    its owner. Defining, removing or undefining methods, alias, changing
    visibility, include/prepend, Module#refine, defining or removing
    constants, registering an autoload, writing the class's own instance
    variables and class variables, Module#freeze and
    Module#set_temporary_name raise Ractor::IsolationError in any other
    Ractor. Reading is unchanged. Everything defined at boot or by the main
    Ractor, required libraries included, is owned by the main Ractor, so a
    non-main Ractor can no longer monkey-patch it; and since defining a constant
    in a foreign class is prohibited, it can not define a top-level class or
    module name either. In exchange a Ractor has full use of the classes it
    creates itself, including unshareable constant, instance variable and class
    variable values, which not even the main Ractor could do before. See
    doc/language/ractor.md. [Feature #22226]

  • Kernel#at_exit and END {} now raise Ractor::IsolationError when called
    in a non-main Ractor. Previously the registered handler ran in the main
    Ractor at process exit, which was confusing. [Feature #22139]

  • Ractor.make_shareable now raises Ractor::Error for an IO object, and
    Ractor.shareable? returns false for it. A frozen IO used to be
    shareable, but almost all of its methods raise FrozenError and it can
    still refer to unshareable objects through the members of rb_io_t.

Stdlib compatibility issues

  • Etc.getlogin on Windows now returns the login name determined when the
    process starts, from the USER or USERNAME environment variable or
    GetUserName(). It used to follow later changes to ENV['USER'].

  • Socket

    • On Windows, a connection that is refused or unreachable now raises the
      matching Errno class as soon as Winsock reports it, instead of
      Errno::ETIMEDOUT once the whole connect_timeout has passed. Code
      rescuing Errno::ETIMEDOUT there has to rescue the real error instead.

    • On Windows, BasicSocket#getsockopt(:SOCKET, :ERROR) now reports an
      errno as it does on the other platforms, instead of the raw WinSock
      error code. Code comparing it with a WSAE* value has to compare it
      with the matching Errno::*::Errno instead.

    [Bug #18661]

Implementation improvements

  • The error_highlight, did_you_mean, and syntax_suggest gems are now
    loaded lazily on the first error display instead of at interpreter
    boot, which reduces startup time. Process.warmup loads them
    eagerly so that pre-forking servers keep their code in
    copy-on-write shared memory. [Feature #21951]

Ractor

A lot of work has gone into making Ractors more stable, performant, and usable. These improvements bring Ractor implementation closer to leaving experimental status.

  • The default GC now runs per Ractor: each Ractor collects its own heap
    on its own thread without stopping the others, and a stop-the-world
    collection only runs when it is really needed (explicit full GC.start,
    shareable-object growth, reclaiming dead Ractors' heaps). Allocation-heavy
    Ractor programs now scale like forked processes.

  • GC.start(global: false) can be used when multiple Ractors are running to force
    a Ractor-local GC. By default, GC.start runs a global GC (all Ractors) like
    before. This can also be triggered with GC.start(global: true). The global
    keyword argument has no effect when a single Ractor is running.

    Visible behavior changes:

    • Ractor#value returns the value only once; a second call raises
      Ractor::Error.
    • [ ]GC.disable/GC.enable act as per-Ractor holds on a process-wide
      switch: one Ractor's GC.enable no longer overrides another Ractor's
      GC.disable.
    • ObjectSpace.each_object enumerates the calling Ractor's own objects
      plus other Ractors' shareable objects (ObjectSpace.dump_all still
      covers everything).
    • ObjectSpace.define_finalizer on another Ractor's object raises
      Ractor::IsolationError.
  • Ractor#monitor now sends an Array naming the Ractor and what happened to
    it, [ractor, :exited] or [ractor, :aborted], where it used to send the
    bare Symbol :exited or :aborted. Several Ractors can then report to one
    port and the receiver still knows which one finished. The Array is built for
    the receiving Ractor, so watching many Ractors leaves no shareable objects
    behind.

    r = Ractor.new { :ok }
    r.monitor(port = Ractor::Port.new)
    port.receive #=> [r, :exited]
    

    One port can therefore watch a whole group, which is all a supervisor
    needs:

    workers.each { |r| r.monitor port }
    
    until workers.empty?
      r, status = port.receive
      workers.delete(r)
      workers << restart(r) if status == :aborted
    end
    

Activity

  1. added this to the JRuby 10.2.0.0 milestone on Sep 30, 2026
  2. headius commented on Sep 30, 2026

    @headius
    MemberAuthor

    I believe Proc#refined has been fully implemented by @shugo so I marked that one as completed.

    @zev Finally got that checklist up! Happy to have your help here if possible!

  3. added a commit that references this issue on Oct 1, 2026
  4. added a commit that references this issue on Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions