3 This document is a list of user-visible feature changes
4 since the **3.0.0** release, except for bug fixes.
6 Note that each entry is kept to a minimum, see links for details.
10 * The block argument can now be anonymous if the block will
11 only be passed to another method. [[Feature #11256]]
19 * Pin operator now takes an expression. [[Feature #17411]]
22 Prime.each_cons(2).lazy.find_all{_1 in [n, ^(n + 2)]}.take(3).to_a
23 #=> [[3, 5], [5, 7], [11, 13]]
26 * Pin operator now supports instance, class, and global variables.
31 Prime.each_cons(2).lazy.find{_1 in [n, ^@n]}
35 * One-line pattern matching is no longer experimental.
37 * Parentheses can be omitted in one-line pattern matching.
47 * Multiple assignment evaluation order has been made consistent with
48 single assignment evaluation order. With single assignment, Ruby
49 uses a left-to-right evaluation order. With this code:
55 The following evaluation order is used:
59 3. `[]=` called on the result of `foo`
61 In Ruby before 3.1.0, multiple assignment did not follow this
62 evaluation order. With this code:
65 foo[0], bar.baz = a, b
68 Versions of Ruby before 3.1.0 would evaluate in the following
74 4. `[]=` called on the result of `foo`
76 6. `baz=` called on the result of `bar`
78 Starting in Ruby 3.1.0, the evaluation order is now consistent with
79 single assignment, with the left-hand side being evaluated before
86 5. `[]=` called on the result of `foo`
87 6. `baz=` called on the result of `bar`
91 * Values in Hash literals and keyword arguments can be omitted.
96 * `{x:, y:}` is a syntax sugar of `{x: x, y: y}`.
97 * `foo(x:, y:)` is a syntax sugar of `foo(x: x, y: y)`.
99 Constant names, local variable names, and method names are allowed as
100 key names. Note that a reserved word is considered as a local
101 variable or method name even if it's a pseudo variable name such as
104 * Non main-Ractors can get instance variables (ivars) of classes/modules
105 if ivars refer to shareable objects.
108 * A command syntax is allowed in endless method definitions, i.e.,
109 you can now write `def foo = puts "Hello"`.
110 Note that `private def foo = puts "Hello"` does not parse.
113 ## Command line options
115 * `--disable-gems` is now explicitly declared as "just for debugging".
116 Never use it in any real-world codebase.
119 ## Core classes updates
121 Note: We're only listing outstanding class updates.
125 * Array#intersect? is added. [[Feature #15198]]
129 * Class#subclasses, which returns an array of classes
130 directly inheriting from the receiver, not
131 including singleton classes.
139 A.subclasses #=> [D, B]
146 * Enumerable#compact is added. [[Feature #17312]]
148 * Enumerable#tally now accepts an optional hash to count. [[Feature #17744]]
150 * Enumerable#each_cons and each_slice to return a receiver. [[GH-1509]]
153 [1, 2, 3].each_cons(2){}
157 [1, 2, 3].each_slice(2){}
164 * Enumerator::Lazy#compact is added. [[Feature #17312]]
168 * File.dirname now accepts an optional argument for the level to
169 strip path components. [[Feature #12194]]
173 * "GC.measure_total_time = true" enables the measurement of GC.
174 Measurement can introduce overhead. It is enabled by default.
175 GC.measure_total_time returns the current setting.
176 GC.stat[:time] or GC.stat(:time) returns measured time
177 in milli-seconds. [[[Feature #10917]]]
179 * GC.total_time returns measured time in nano-seconds. [[[Feature #10917]]]
183 * Integer.try_convert is added. [[Feature #15211]]
188 * Kernel#load now accepts a module as the second argument,
189 and will load the file using the given module as the
190 top-level module. [[Feature #6210]]
194 * Marshal.load now accepts a `freeze: true` option.
195 All returned objects are frozen except for `Class` and
196 `Module` instances. Strings are deduplicated. [[Feature #18148]]
200 * MatchData#match is added [[Feature #18172]]
202 * MatchData#match_length is added [[Feature #18172]]
204 * Method/UnboundMethod
206 * Method#public?, Method#private?, Method#protected?,
207 UnboundMethod#public?, UnboundMethod#private?,
208 UnboundMethod#protected? have been added. [[Feature #11689]]
212 * Module#prepend now modifies the ancestor chain if the receiver
213 already includes the argument. Module#prepend still does not
214 modify the ancestor chain if the receiver has already prepended
215 the argument. [[Bug #17423]]
217 * Module#private, #public, #protected, and #module_function will
218 now return their arguments. If a single argument is given, it
219 is returned. If no arguments are given, nil is returned. If
220 multiple arguments are given, they are returned as an array.
225 * Process.\_fork is added. This is a core method for fork(2).
226 Do not call this method directly; it is called by existing
227 fork methods: Kernel.#fork, Process.fork, and IO.popen("-").
228 Application monitoring libraries can overwrite this method to
229 hook fork events. [[Feature #17795]]
233 * Passing only keyword arguments to Struct#initialize is warned.
234 You need to use a Hash literal to set a Hash to a first member.
237 * StructClass#keyword_init? is added [[Feature #18008]]
241 * Update Unicode version to 13.0.0 [[Feature #17750]]
242 and Emoji version to 13.0 [[Feature #18029]]
244 * String#unpack and String#unpack1 now accept an `offset:` keyword
245 argument to start the unpacking after an arbitrary number of bytes
246 have been skipped. If `offset` is outside of the string bounds
247 `ArgumentError` is raised. [[Feature #18254]]
251 * Queue#initialize now accepts an Enumerable of initial values.
256 * Thread#native_thread_id is added. [[Feature #17853]]
260 * Thread::Backtrace.limit, which returns the value to limit backtrace
261 length set by `--backtrace-limit` command line option, is added.
266 * Time.new now accepts optional `in:` keyword argument for the
267 timezone, as well as `Time.at` and `Time.now`, so that is now
268 you can omit minor arguments to `Time.new`. [[Feature #17485]]
270 * Time#strftime supports RFC 3339 UTC for unknown offset local
271 time, `-0000`, as `%-z`. [[Feature #17544]]
275 * TracePoint.allow_reentry is added to allow reenter while TracePoint
281 * $LOAD_PATH.resolve_feature_path does not raise. [[Feature #16043]]
285 * Add support for `Addrinfo.getaddrinfo` using `address_resolve` hook.
288 * Introduce non-blocking `Timeout.timeout` using `timeout_after` hook.
291 * Introduce new scheduler hooks `io_read` and `io_write` along with a
292 low level `IO::Buffer` for zero-copy read/write. [[Feature #18020]]
294 * IO hooks `io_wait`, `io_read`, `io_write`, receive the original IO object
295 where possible. [[Bug #18003]]
297 * Make `Monitor` fiber-safe. [[Bug #17827]]
299 * Replace copy coroutine with pthread implementation. [[Feature #18015]]
303 * New class which represents a module created by Module#refine.
304 `include` and `prepend` are deprecated, and `import_methods` is added
305 instead. [[Bug #17429]]
309 * The following default gem are updated.
322 * error_highlight 0.3.0
349 * reline 0.2.8.pre.11
352 * ruby2_keywords 0.0.5
365 * The following bundled gems are updated.
373 * The following default gems are now bundled gems.
382 * Coverage measurement now supports suspension. You can use `Coverage.suspend`
383 to stop the measurement temporarily, and `Coverage.resume` to restart it.
384 See [[Feature #18176]] in detail.
386 * Random::Formatter is moved to random/formatter.rb, so that you can
387 use `Random#hex`, `Random#base64`, and so on without SecureRandom.
390 ## Compatibility issues
392 Note: Excluding feature bug fixes.
394 * `rb_io_wait_readable`, `rb_io_wait_writable` and `rb_wait_for_single_fd` are
395 deprecated in favour of `rb_io_maybe_wait_readable`,
396 `rb_io_maybe_wait_writable` and `rb_io_maybe_wait` respectively.
397 `rb_thread_wait_fd` and `rb_thread_fd_writable` are deprecated. [[Bug #18003]]
399 ## Stdlib compatibility issues
401 * `ERB#initialize` warns `safe_level` and later arguments even without -w.
404 * `lib/debug.rb` is replaced with `debug.gem`
406 * `Kernel#pp` in `lib/pp.rb` uses the width of `IO#winsize` by default.
407 This means that the output width is automatically changed depending on
408 your terminal size. [[Feature #12913]]
410 * Psych 4.0 changes `Psych.load` as `safe_load` by the default.
411 You may need to use Psych 3.3.2 for migrating to this behavior.
416 * Documented. [[GH-4815]]
418 * `rb_gc_force_recycle` is deprecated and has been changed to a no-op.
421 ## Implementation improvements
423 * Inline cache mechanism is introduced for reading class variables.
426 * `instance_eval` and `instance_exec` now only allocate a singleton class when
427 required, avoiding extra objects and improving performance. [[GH-5146]]
429 * The performance of `Struct` accessors is improved. [[GH-5131]]
431 * `mandatory_only?` builtin special form to improve performance on
432 builtin methods. [[GH-5112]]
434 * Experimental feature Variable Width Allocation in the garbage collector.
435 This feature is turned off by default and can be enabled by compiling Ruby
436 with flag `USE_RVARGC=1` set. [[Feature #18045]] [[Feature #18239]]
440 * Rename Ruby 3.0's `--jit` to `--mjit`, and alias `--jit` to `--yjit`
441 on non-Windows x86-64 platforms and to `--mjit` on others.
445 * The default `--mjit-max-cache` is changed from 100 to 10000.
447 * JIT-ed code is no longer cancelled when a TracePoint for class events
450 * The JIT compiler no longer skips compilation of methods longer than
453 * `--mjit-verbose` and `--mjit-warning` output "JIT cancel" when JIT-ed
454 code is disabled because TracePoint or GC.compact is used.
456 ### YJIT: New experimental in-process JIT compiler
458 New JIT compiler available as an experimental feature. [[Feature #18229]]
460 See [this blog post](https://shopify.engineering/yjit-just-in-time-compiler-cruby
461 ) introducing the project.
463 * Disabled by default, use `--yjit` command-line option to enable YJIT.
465 * Performance improvements on benchmarks based on real-world software,
466 up to 22% on railsbench, 39% on liquid-render.
468 * Fast warm-up times.
470 * Limited to Unix-like x86-64 platforms for now.
476 * Generics type parameters can be bounded ([PR](https://github.com/ruby/rbs/pull/844)).
479 # `T` must be compatible with the `_Output` interface.
480 # `PrettyPrint[String]` is ok, but `PrettyPrint[Integer]` is a type error.
481 class PrettyPrint[T < _Output]
483 def <<: (String) -> void
486 attr_reader output: T
488 def initialize: (T output) -> void
492 * Type aliases can be generic. ([PR](https://github.com/ruby/rbs/pull/823))
495 # Defines a generic type `list`.
496 type list[T] = [ T, list[T] ]
499 type str_list = list[String]
500 type int_list = list[Integer]
503 * [rbs collection](https://github.com/ruby/rbs/blob/master/docs/collection.md) has been introduced to manage gems’ RBSs.
505 * Many signatures for built-in and standard libraries have been added/updated.
507 * It includes many bug fixes and performance improvements too.
509 See the [CHANGELOG.md](https://github.com/ruby/rbs/blob/master/CHANGELOG.md) for more information.
513 * [Experimental IDE support](https://github.com/ruby/typeprof/blob/master/doc/ide.md) has been implemented.
514 * Many bug fixes and performance improvements since Ruby 3.0.0.
518 * A new debugger [debug.gem](https://github.com/ruby/debug) is bundled.
519 debug.gem is a fast debugger implementation, and it provides many features
520 like remote debugging, colorful REPL, IDE (VSCode) integration, and more.
521 It replaces `lib/debug.rb` standard library.
523 * `rdbg` command is also installed into `bin/` directory to start and control
528 A built-in gem called error_highlight has been introduced.
529 It shows fine-grained error locations in the backtrace.
531 Example: `title = json[:article][:title]`
533 If `json` is nil, it shows:
537 test.rb:2:in `<main>': undefined method `[]' for nil:NilClass (NoMethodError)
539 title = json[:article][:title]
543 If `json[:article]` returns nil, it shows:
547 test.rb:2:in `<main>': undefined method `[]' for nil:NilClass (NoMethodError)
549 title = json[:article][:title]
553 This feature is enabled by default.
554 You can disable it by using a command-line option `--disable-error_highlight`.
555 See [the repository](https://github.com/ruby/error_highlight) in detail.
557 ## Miscellaneous changes
559 * lib/objspace/trace.rb is added, which is a tool for tracing the object
560 allocation. Just by requiring this file, tracing is started *immediately*.
561 Just by `Kernel#p`, you can investigate where an object was created.
562 Note that just requiring this file brings a large performance overhead.
563 This is only for debugging purposes. Do not use this in production.
566 * Now exceptions raised in finalizers will be printed to `STDERR`, unless
567 `$VERBOSE` is `nil`. [[Feature #17798]]
569 * `ruby -run -e httpd` displays URLs to access. [[Feature #17847]]
571 * Add `ruby -run -e colorize` to colorize Ruby code using
572 `IRB::Color.colorize_code`.
574 [Bug #4443]: https://bugs.ruby-lang.org/issues/4443
575 [Feature #6210]: https://bugs.ruby-lang.org/issues/6210
576 [Feature #10917]: https://bugs.ruby-lang.org/issues/10917
577 [Feature #11256]: https://bugs.ruby-lang.org/issues/11256
578 [Feature #11689]: https://bugs.ruby-lang.org/issues/11689
579 [Feature #12194]: https://bugs.ruby-lang.org/issues/12194
580 [Feature #12495]: https://bugs.ruby-lang.org/issues/12495
581 [Feature #12913]: https://bugs.ruby-lang.org/issues/12913
582 [Feature #14256]: https://bugs.ruby-lang.org/issues/14256
583 [Feature #14579]: https://bugs.ruby-lang.org/issues/14579
584 [Feature #15198]: https://bugs.ruby-lang.org/issues/15198
585 [Feature #15211]: https://bugs.ruby-lang.org/issues/15211
586 [Feature #15912]: https://bugs.ruby-lang.org/issues/15912
587 [Feature #16043]: https://bugs.ruby-lang.org/issues/16043
588 [Feature #16182]: https://bugs.ruby-lang.org/issues/16182
589 [Feature #16806]: https://bugs.ruby-lang.org/issues/16806
590 [Feature #17312]: https://bugs.ruby-lang.org/issues/17312
591 [Feature #17327]: https://bugs.ruby-lang.org/issues/17327
592 [Feature #17370]: https://bugs.ruby-lang.org/issues/17370
593 [Feature #17398]: https://bugs.ruby-lang.org/issues/17398
594 [Feature #17411]: https://bugs.ruby-lang.org/issues/17411
595 [Bug #17423]: https://bugs.ruby-lang.org/issues/17423
596 [Bug #17429]: https://bugs.ruby-lang.org/issues/17429
597 [Feature #17470]: https://bugs.ruby-lang.org/issues/17470
598 [Feature #17479]: https://bugs.ruby-lang.org/issues/17479
599 [Feature #17485]: https://bugs.ruby-lang.org/issues/17485
600 [Feature #17544]: https://bugs.ruby-lang.org/issues/17544
601 [Feature #17592]: https://bugs.ruby-lang.org/issues/17592
602 [Feature #17684]: https://bugs.ruby-lang.org/issues/17684
603 [Feature #17724]: https://bugs.ruby-lang.org/issues/17724
604 [Feature #17744]: https://bugs.ruby-lang.org/issues/17744
605 [Feature #17750]: https://bugs.ruby-lang.org/issues/17750
606 [Feature #17762]: https://bugs.ruby-lang.org/issues/17762
607 [Feature #17763]: https://bugs.ruby-lang.org/issues/17763
608 [Feature #17795]: https://bugs.ruby-lang.org/issues/17795
609 [Feature #17798]: https://bugs.ruby-lang.org/issues/17798
610 [Bug #17827]: https://bugs.ruby-lang.org/issues/17827
611 [Feature #17847]: https://bugs.ruby-lang.org/issues/17847
612 [Feature #17853]: https://bugs.ruby-lang.org/issues/17853
613 [Bug #17866]: https://bugs.ruby-lang.org/issues/17866
614 [Bug #18003]: https://bugs.ruby-lang.org/issues/18003
615 [Feature #18008]: https://bugs.ruby-lang.org/issues/18008
616 [Feature #18015]: https://bugs.ruby-lang.org/issues/18015
617 [Feature #18020]: https://bugs.ruby-lang.org/issues/18020
618 [Feature #18029]: https://bugs.ruby-lang.org/issues/18029
619 [Feature #18045]: https://bugs.ruby-lang.org/issues/18045
620 [Feature #18148]: https://bugs.ruby-lang.org/issues/18148
621 [Feature #18172]: https://bugs.ruby-lang.org/issues/18172
622 [Feature #18176]: https://bugs.ruby-lang.org/issues/18176
623 [Feature #18190]: https://bugs.ruby-lang.org/issues/18190
624 [Feature #18229]: https://bugs.ruby-lang.org/issues/18229
625 [Feature #18239]: https://bugs.ruby-lang.org/issues/18239
626 [Feature #18254]: https://bugs.ruby-lang.org/issues/18254
627 [Feature #18273]: https://bugs.ruby-lang.org/issues/18273
628 [Feature #18290]: https://bugs.ruby-lang.org/issues/18290
630 [GH-1509]: https://github.com/ruby/ruby/pull/1509
631 [GH-4815]: https://github.com/ruby/ruby/pull/4815
632 [GH-5112]: https://github.com/ruby/ruby/pull/5112
633 [GH-5131]: https://github.com/ruby/ruby/pull/5131
634 [GH-5146]: https://github.com/ruby/ruby/pull/5146