ruby/spec already contains some specs for 3.4, but we should aim to cover all new features and important changes.
This will improve the test coverage of these features (and maybe discover a few bugs along the way), allow other Ruby implementations to implement the changes faster with more confidence and document clearly the new behavior.
The new specs should be within a version guard block:
ruby_version_is "3.4" do
# New specs
end
NOTE: https://rubyreferences.github.io/rubychanges/3.4.html gives more details for many features and changes.
Notes:
- Ractor & RubyVM related changes are removed since they are CRuby-specific.
From https://github.com/ruby/ruby/blob/master/doc/NEWS/NEWS-4.0.0.md:
NEWS for Ruby 4.0.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
Core classes updates
Note: We're only listing outstanding class updates.
Array
Binding
Enumerator
ErrorHighlight
Fiber
Fiber::Scheduler
File
IO
Kernel
Math
Pathname
Proc
Range
Ruby
Set
Socket
String
Thread
Compatibility issues
Stdlib compatibility issues
C API updates
IO
GVL
Set
ruby/spec already contains some specs for 3.4, but we should aim to cover all new features and important changes.
This will improve the test coverage of these features (and maybe discover a few bugs along the way), allow other Ruby implementations to implement the changes faster with more confidence and document clearly the new behavior.
The new specs should be within a version guard block:
NOTE: https://rubyreferences.github.io/rubychanges/3.4.html gives more details for many features and changes.
Notes:
From https://github.com/ruby/ruby/blob/master/doc/NEWS/NEWS-4.0.0.md:
NEWS for Ruby 4.0.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
*nilno longer callsnil.to_a, similar to how**nildoesnot call
nil.to_hash. [Feature #21047]Logical binary operators (
||,&&,andandor) at thebeginning of a line continue the previous line, like fluent dot.
The following code examples are equal:
Previously:
[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, andBinding#local_variable_defined?reject to handle numbered parameters.[Bug #21049]
Binding#implicit_parameters,Binding#implicit_parameter_get, andBinding#implicit_parameter_defined?have been added to accessnumbered parameters and "it" parameter. [Bug #21049]
Enumerator
Enumerator.producenow accepts an optionalsizekeyword argumentto specify the size of the enumerator. It can be an integer,
Float::INFINITY, a callable object (such as a lambda), orniltoindicate unknown size. When not specified, the size defaults to
Float::INFINITY.[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]
Fiber
Fiber#raise(cause:)argument similar toKernel#raise. [Feature #21360]Fiber::Scheduler
Introduce
Fiber::Scheduler#fiber_interruptto interrupt a fiber with agiven 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 tocontinue 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 statxsystem 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 methodswith 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:[Feature #21219]
A deprecated behavior, process creation by
Kernel#openwith aleading
|, was removed. [Feature #19630]Math
Math.log1pandMath.expm1are added. [Feature #21527]Pathname
[Feature #17473]
Proc
Proc#parametersnow shows anonymous optional parameters as[:opt]instead of
[:opt, nil], making the output consistent with when theanonymous parameter is required. [Bug #20974]
Range
Range#to_setnow performs size checks to prevent issues withendless ranges. [Bug #21654]
Range#overlap?now correctly handles infinite (unbounded) ranges.[Bug #21185]
Range#maxbehavior on beginless integer ranges has been fixed.[Bug #21174] [Bug #21175]
Ruby
Rubyhas been defined, which containsRuby-related constants. This module was reserved in Ruby 3.4
and is now officially defined. [Feature #20884]
Set
Setis now a core class, instead of an autoloaded stdlib class.[Feature #21216]
Set#inspectnow uses a simpler display, similar to literal arrays.(e.g.,
Set[1, 2, 3]instead of#<Set: {1, 2, 3}>). [Feature #21389]Passing arguments to
Set#to_setandEnumerable#to_setis now deprecated.[Feature #21390]
Socket
Socket.tcp&TCPSocket.newaccepts anopen_timeoutkeyword argument to specifythe timeout for the initial connection. [Feature #21347]
TCPSocket.new, eitherErrno::ETIMEDOUTor
IO::TimeoutErrorcould previously be raised depending on the situation.This behavior has been unified so that
IO::TimeoutErroris now consistently raised.(Please note that, in
Socket.tcp, there are still cases whereErrno::ETIMEDOUTmay be raised in similar situations, and that in both cases
Errno::ETIMEDOUTmay beraised when the timeout occurs at the OS level.)
String
Update Unicode to Version 17.0.0 and Emoji Version 17.0.
[Feature #19908][Feature #20724][Feature #21275] (also applies to Regexp)
String#strip,strip!,lstrip,lstrip!,rstrip, andrstrip!are extended to accept
*selectorsarguments. [Feature #21552]Thread
Thread#raise(cause:)argument similar toKernel#raise. [Feature #21360]Compatibility issues
ObjectSpace._id2refis deprecated. [Feature #15408]Process::Status#&andProcess::Status#>>have been removed.They were deprecated in Ruby 3.3. [Bug #19868]
rb_path_checkhas been removed. This function was used for$SAFEpath checking which was removed in Ruby 2.7,and was already deprecated.
[Feature #20971]
A backtrace for
ArgumentErrorof "wrong number of arguments" nowinclude the receiver's class or module name (e.g., in
Foo#barinstead of in
bar). [Bug #21698]Backtraces no longer display
internalframes.These methods now appear as if it is in the Ruby source file,
consistent with other C-implemented methods. [Bug #20968]
Before:
After:
Stdlib compatibility issues
CGI library is removed from the default gems. Now we only provide
cgi/escapeforthe following methods:
CGI.escapeandCGI.unescapeCGI.escapeHTMLandCGI.unescapeHTMLCGI.escapeURIComponentandCGI.unescapeURIComponentCGI.escapeElementandCGI.unescapeElement[Feature #21258]
With the move of
Setfrom stdlib to core class,set/sorted_set.rbhasbeen removed, and
SortedSetis no longer an autoloaded constant. Pleaseinstall the
sorted_setgem andrequire 'sorted_set'to useSortedSet.[Feature #21287]
C API updates
IO
rb_thread_fd_closeis deprecated and now a no-op. If you need to exposefile descriptors from C extensions to Ruby code, create an
IOinstanceusing
RUBY_IO_MODE_EXTERNALand userb_io_close(io)to close it (thisalso interrupts and waits for all pending operations on the
IOinstance). Directly closing file descriptors does not interrupt pending
operations, and may lead to undefined behaviour. In other words, if two
IOobjects share the same file descriptor, closing one does not affectthe other. [Feature #18455]
GVL
rb_thread_call_with_gvlnow works with or without the GVL.This allows gems to avoid checking
ruby_thread_has_gvl_p.Please still be diligent about the GVL. [Feature #20750]
Set
A C API for
Sethas been added. The following methods are supported:[Feature #21459]
rb_set_foreachrb_set_newrb_set_new_caparb_set_lookuprb_set_addrb_set_clearrb_set_deleterb_set_size