NEWS for Ruby 3.5.0
This document is a list of user-visible feature changes since the 3.4.0 release, except for bug fixes.
Note that each entry is kept to a minimum, see links for details.
Language changes
*nil
no longer callsnil.to_a
, similar to how**nil
does not callnil.to_hash
. [Feature #21047]Logical binary operators (
||
,&&
,and
andor
) at the beginning of a line continue the previous line, like fluent dot. The following two code are equal:if condition1 && condition2 #... end
if condition1 && condition2 #... end
Core classes updates
Note: We're only listing outstanding class updates.
Kernel
Kernel#inspect
now checks for the existence of a#instance_variables_to_inspect
method, allowing control over which instance variables are displayed in the#inspect
string: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 #=> #<DatabaseConfig:0x0000000104def350 @host="localhost", @user="root">
Binding
Binding#local_variables
does no longer include numbered parameters. Also,Binding#local_variable_get
andBinding#local_variable_set
reject to handle numbered parameters. [Bug #21049]
IO
IO.select
acceptsFloat::INFINITY
as a timeout argument. [Feature #20610]
Math
Math.log1p
andMath.expm1
are added. [Feature #21527]
Socket
Socket.tcp
&TCPSocket.new
acceptsopen_timeout
as a keyword argument to specify the timeout for the initial connection. [Feature #21347]
Ractor
Ractor::Port
class was added for a new synchronization mechanism to communicate between Ractors. [Feature #21262]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
Ractor::Port
provides the following methods:Ractor::Port#receive
Ractor::Port#send
(orRactor::Port#<<
)Ractor::Port#close
Ractor::Port#closed?
As result,
Ractor.yield
andRactor#take
were removed.Ractor#join
andRactor#value
were added to wait for the termination of a Ractor. These are similar toThread#join
andThread#value
.Ractor#monitor
andRactor#unmonitor
were added as low-level interfaces used internally to implementRactor#join
.Ractor.select
now only accepts Ractors and Ports. If Ractors are given, it returns when a Ractor terminates.Ractor#default_port
was added. EachRactor
has a default port, which is used byRactor.send
,Ractor.receive
.Ractor#close_incoming
andRactor#close_outgoing
were removed.
Set
Set
is now a core class, instead of an autoloaded stdlib class. [Feature #21216]
String
- Update Unicode to Version 16.0.0 and Emoji Version 16.0. [Feature #19908]Feature #20724
Thread
- Introduce support for
Thread#raise(cause:)
argument similar toKernel#raise
. [Feature #21360]
- Introduce support for
Fiber
- Introduce support for
Fiber#raise(cause:)
argument similar toKernel#raise
. [Feature #21360]
- Introduce support for
Fiber::Scheduler
- Introduce
Fiber::Scheduler#fiber_interrupt
to 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
Pathname
- Pathname has been promoted from a default gem to a core class of Ruby. [Feature #17473]
Stdlib updates
The following bundled gems are promoted from default gems.
- ostruct 0.6.3
- pstore 0.2.0
- benchmark 0.4.1
- logger 1.7.0
- rdoc 6.14.2
- win32ole 1.9.2
- irb 1.15.2
- reline 0.6.2
- readline 0.0.4
- fiddle 1.1.8
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.3.0 if it has GitHub releases.
The following default gem is added.
- win32-registry 0.1.0
The following default gems are updated.
- RubyGems 3.8.0.dev
- bundler 2.8.0.dev
- erb 5.0.2
- etc 1.4.6
- fcntl 1.3.0
- io-console 0.8.1
- io-nonblock 0.3.2
- io-wait 0.3.2
- json 2.13.2
- optparse 0.7.0.dev.2
- prism 1.5.1
- psych 5.2.6
- resolv 0.6.2
- stringio 3.1.8.dev
- strscan 3.1.6.dev
- uri 1.0.3
- weakref 0.1.4
The following bundled gems are added.
The following bundled gems are updated.
- minitest 5.25.5
- rake 13.3.0
- test-unit 3.7.0
- rexml 3.4.2
- net-imap 0.5.10
- net-smtp 0.5.1
- matrix 0.4.3
- prime 0.1.4
- rbs 3.9.4
- debug 1.11.0
- base64 0.3.0
- bigdecimal 3.2.2
- drb 2.2.3
- syslog 0.3.0
- csv 3.3.5
- repl_type_completor 0.1.11
Supported platforms
Compatibility issues
The following methods were removed from Ractor due because of
Ractor::Port
:Ractor.yield
Ractor#take
Ractor#close_incoming
Ractor#close_outgoging
ObjectSpace._id2ref
is deprecated. [Feature #15408]
Stdlib compatibility issues
CGI library is removed from the default gems. Now we only provide
cgi/escape
for the following methods:CGI.escape
andCGI.unescape
CGI.escapeHTML
andCGI.unescapeHTML
CGI.escapeURIComponent
andCGI.unescapeURIComponent
CGI.escapeElement
andCGI.unescapeElement
With the move of
Set
from stdlib to core class,set/sorted_set.rb
has been removed, andSortedSet
is no longer an autoloaded constant. Please install thesorted_set
gem andrequire 'sorted_set'
to useSortedSet
. [Feature #21287]
C API updates
IO
rb_thread_fd_close
is deprecated and now a no-op. If you need to expose file descriptors from C extensions to Ruby code, create anIO
instance usingRUBY_IO_MODE_EXTERNAL
and userb_io_close(io)
to close it (this also interrupts and waits for all pending operations on theIO
instance). Directly closing file descriptors does not interrupt pending operations, and may lead to undefined behaviour. In other words, if twoIO
objects share the same file descriptor, closing one does not affect the other. [Feature #18455]
Implementation improvements
Ractor
A lot of work has gone into making Ractors more stable, performant, and usable. These improvements bring Ractors implementation closer to leaving experimental status.
- Performance improvements
- Frozen strings and the symbol table internally use a lock-free hash set
- Method cache lookups avoid locking in most cases
- Class (and geniv) instance variable access is faster and avoids locking
- Cache contention is avoided during object allocation
object_id
avoids locking in most cases
- Bug fixes and stability
- Fixed possible deadlocks when combining Ractors and Threads
- Fixed issues with require and autoload in a Ractor
- Fixed encoding/transcoding issues across Ractors
- Fixed race conditions in GC operations and method invalidation
- Fixed issues with processes forking after starting a Ractor
JIT
- YJIT
- YJIT stats
ratio_in_yjit
no longer works in the default build. Use--enable-yjit=stats
onconfigure
to enable it on--yjit-stats
.- Add
invalidate_everything
to default stats, which is incremented when every code is invalidated by TracePoint.
- Add
mem_size:
andcall_threshold:
options toRubyVM::YJIT.enable
.
- YJIT stats
- ZJIT
- Add an experimental method-based JIT compiler.
Use
--enable-zjit
onconfigure
to enable the--zjit
support. - As of Ruby 3.5.0-preview2, ZJIT is not yet ready for speeding up most benchmarks. Please refrain from evaluating ZJIT just yet. Stay tuned for the Ruby 3.5 release.
- Add an experimental method-based JIT compiler.
Use
- RJIT
--rjit
is removed. We will move the implementation of the third-party JIT API to the ruby/rjit repository.