Skip to content

Commit a84ca3f

Browse files
authored
Ruby 3.2 changes (#49)
Including updates to Ruby Evolution
1 parent a90ac49 commit a84ca3f

22 files changed

Lines changed: 4219 additions & 67 deletions

2.4.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ description: Ruby 2.4 full and annotated changelog
1616
-->
1717

1818
* **Released at:** Dec 25, 2016 (<a class="github" href="https://github.com/ruby/ruby/blob/trunk/doc/NEWS-2.4.0">NEWS</a> file)
19-
* **Status (as of Jul 09, 2022):** EOL, latest is 2.4.10
19+
* **Status (as of Feb 04, 2023):** EOL, latest is 2.4.10
2020
* **This document first published:** Oct 14, 2019
21-
* **Last change to this document:** Jul 09, 2022
21+
* **Last change to this document:** Feb 04, 2023
2222

2323
## Highlights[](#highlights)
2424

2.5.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ description: Ruby 2.5 full and annotated changelog
1616
-->
1717

1818
* **Released at:** Dec 25, 2017 (<a class="github" href="https://github.com/ruby/ruby/blob/trunk/doc/NEWS-2.5.0">NEWS</a> file)
19-
* **Status (as of Jul 09, 2022):** EOL, latest is 2.5.9
19+
* **Status (as of Feb 04, 2023):** EOL, latest is 2.5.9
2020
* **This document first published:** Jun 6, 2019
21-
* **Last change to this document:** Jul 09, 2022
21+
* **Last change to this document:** Feb 04, 2023
2222

2323
## Highlights[](#highlights)
2424

@@ -145,7 +145,7 @@ When `uplevel: N` provided to `Kernel#warn`, the warning message includes the fi
145145

146146
Ruby 2.4 introduced redefinable `Warning.warn` method, which allowed to control how warnings are handled. But `warn` method wasn't calling it, so initially only warnings issued from C code could've been handled. 2.5 fixes it. <small>(Was not mentioned in NEWS-2.5.0)</small>
147147

148-
* **Discussion:** [Feature #12299, comment #14-15](https://bugs.ruby-lang.org/issues/12299#note-14)
148+
* **Discussion:** <a class="tracker feature" href="https://bugs.ruby-lang.org/issues/12299#note-14#note-14">Feature #12299<small>#note-14</small></a>
149149
* **Documentation:**
150150
* **Code:**
151151
```ruby
@@ -375,7 +375,9 @@ The underlying <a class="github" href="https://github.com/k-takata/Onigmo">Onigm
375375
ModernPerson.new('Meredith', 'Williams', 28)
376376
# ArgumentError (wrong number of arguments (given 3, expected 0))
377377
```
378-
* **Follow-up:** Ruby 3.1 introduced [a method](3.1.html#structclasskeyword_init) to check whether some struct should be initialized with keyword arguments, and [a warning](3.1.html#warning-on-passing-keywords-to-a-non-keyword-initialized-struct) on erroneous initialization of non-keyword-args struct with a hash.
378+
* **Follow-ups:**
379+
* Ruby 3.1 introduced [a method](3.1.html#structclasskeyword_init) to check whether some struct should be initialized with keyword arguments, and [a warning](3.1.html#warning-on-passing-keywords-to-a-non-keyword-initialized-struct) on erroneous initialization of non-keyword-args struct with a hash.
380+
* Ruby 3.2 [allowed](3.2.html#struct-can-be-initialized-by-keyword-arguments-by-default) all structs without explicit `keyword_init:` parameter specified to be initialized by both positional and keyword args.
379381

380382
### `Time.at`: units[](#timeat-units)
381383

@@ -637,6 +639,11 @@ The constant `TMPFILE` is <a class="ruby-doc" href="https://ruby-doc.org/core-2.
637639
# Ruby 2.4: => "/tmp" -- what???
638640
# Ruby 2.5: IOError (File is unnamed (TMPFILE?))
639641
```
642+
* **Follow-up:** Ruby 3.2 [introduced](3.2.html#iopath) a concept of generic `IO#path` which is allowed to be `nil` when the path is unknown, so the behavior changed:
643+
```ruby
644+
f = File.open('/tmp', File::RDWR | File::TMPFILE)
645+
f.path #=> nil
646+
```
640647

641648
#### `File.lutime`[](#filelutime)
642649

@@ -698,7 +705,7 @@ Much akin to `Hash#fetch`, allows to fetch thread-local variable or provide defa
698705
### Misc[](#misc)
699706

700707
* `Random.raw_seed` renamed to <a class="ruby-doc" href="https://ruby-doc.org/core-2.5.0/Random.html#method-c-urandom"><code>Random.urandom</code></a>. Discussion: <a class="tracker bug" href="https://bugs.ruby-lang.org/issues/9569">Bug #9569</a>.
701-
* `Data` is deprecated. It was a base class for C extensions, and it's not necessary to expose in Ruby level. <a class="tracker feature" href="https://bugs.ruby-lang.org/issues/3072">Feature #3072</a>. **Follow-up:** Fully removed in 3.0.
708+
* `Data` is deprecated. It was a base class for C extensions, and it's not necessary to expose in Ruby level. <a class="tracker feature" href="https://bugs.ruby-lang.org/issues/3072">Feature #3072</a>. **Follow-up:** Fully removed in 3.0; in 3.2, a new class with the same name but different meaning was [reintroduced](3.2.html#data-new-immutable-value-object-class).
702709

703710
## Standard library[](#standard-library)
704711

2.6.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ description: Ruby 2.6 full and annotated changelog
88
# Ruby 2.6
99

1010
* **Released at:** Dec 25, 2018 (<a class="github" href="https://github.com/ruby/ruby/blob/ruby_2_6/NEWS">NEWS</a> file)
11-
* **Status (as of Jul 09, 2022):** EOL, latest is 2.6.10
11+
* **Status (as of Feb 04, 2023):** EOL, latest is 2.6.10
1212
* **This document first published:** Dec 29, 2018
13-
* **Last change to this document:** Jul 09, 2022
13+
* **Last change to this document:** Feb 04, 2023
1414

1515
> **Note:** As already explained in [Introduction](README.md), this site is dedicated to changes in the **language**, not the **implementation**, therefore the list below lacks mentions of lots of important optimization introduced in 2.6, including the whole JIT big thing. That's not because they are not important, just because this site's goals are different.
1616
@@ -472,6 +472,7 @@ Several enumerators can now be chained into one with `Enumerator#+(other)` or `E
472472
# or redirected with `ruby test.rb 2> err.log
473473
end
474474
```
475+
* **Follow-up:** In Ruby 3.2, one more related method `#detailed_message` [was added](3.2.html#exceptiondetailed_message).
475476

476477
#### Exception output tweaking[](#exception-output-tweaking)
477478

@@ -597,7 +598,10 @@ The new module provides an "official" Ruby parser, replacing stdlib Ripper (and
597598
tree.children[2].children[0].children
598599
# => [1]
599600
```
600-
* **Notice:** One may be excited about `RubyVM::AbstractSyntaxTree.of(proc)`, but it doesn't mean the "real" extraction of code from live `Proc`, rather a simple hack with trying to find proc's source file and parse it.
601+
* **Note:** One may be excited about `RubyVM::AbstractSyntaxTree.of(proc)`, but it doesn't mean the "real" extraction of code from live `Proc`, rather a simple hack with trying to find proc's source file and parse it.
602+
* **Follow-up:** In Ruby 3.2, new options were added for `parse`, allowing to:
603+
* Perform [fault-tolerant parsing](3.2.html#error_tolerant-true-option-for-parsing) (parse syntactically wrong/incomplete code);
604+
* [Preserve tokens](3.2.html#keep_tokens-true-option-for-parsing) from source code alongside nodes;
601605

602606
### `TracePoint` improvements[](#tracepoint-improvements)
603607

@@ -669,6 +673,9 @@ With new parameters provided, you can fine-tune for what methods or specific lin
669673
```
670674
* **Notice:** In absence of docs, we can at least point at [commit message](https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/66003):
671675
> `code` should be consisted of `InstructionSequence` (iseq) (`RubyVM::InstructionSequence.of(code)` should not return nil). If code is a tree of iseq, `TracePoint` is enabled on all of iseqs in a tree.
676+
* **Follow-ups:**
677+
* In 2.7, <a class="ruby-doc" href="https://docs.ruby-lang.org/en/2.7.0/TracePoint.html#method-i-enable">the docs</a> have emerged, and a new parameter named `target_thread:` was introduced. It was missing from the official `NEWS`-file and therefore missing from this changelog _(which is a thing to be fixed!)_
678+
* In 3.2, `target_thread:` began [defaulting to the current thread](3.2.html#tracepoint-for-block-default-to-trace-the-current-thread) with block form of `enable`.
672679

673680
## Standard library[](#standard-library)
674681

2.7.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ description: Ruby 2.7 full and annotated changelog
88
# Ruby 2.7
99

1010
* **Released at:** Dec 25, 2019 (<a class="github" href="https://github.com/ruby/ruby/blob/ruby_2_7/NEWS">NEWS</a> file)
11-
* **Status (as of Jul 09, 2022):** 2.7.6 is current _stable_
11+
* **Status (as of Feb 04, 2023):** 2.7.7 is current _stable_
1212
* **This document first published:** Dec 27, 2019
13-
* **Last change to this document:** Jul 09, 2022
13+
* **Last change to this document:** Feb 04, 2023
1414

1515
<!-- TODO: all links to docs should be replaced with /2.7.0/ suffix instead of /master/ when 2.7.0 would be published -->
1616

@@ -48,7 +48,10 @@ data in [{user: {login:}, title:, created_at:}, *] # match array of hashes, with
4848
# => ["zverok", "Add pattern matching documentation", "2019-12-25T18:42:03Z"]
4949
```
5050

51-
* **Follow-up:** Pattern matching became a stable (non-experimental) feature, and its power expanded signficantly [in 3.0](#pattern-matching); and then it became even more flexible [in 3.1](3.1.html#pattern-matching).
51+
* **Follow-ups:**
52+
* Pattern matching became a stable (non-experimental) feature, and its power expanded signficantly [in 3.0](#pattern-matching);
53+
* Then, it became even more flexible [in 3.1](3.1.html#pattern-matching);
54+
* In 3.2, several core and standard library classes (`MatchData`, `Time`, `Date`, `DateTime`) [became deconstructible](3.2.html#pattern-matching).
5255

5356
### Keyword argument-related changes[](#keyword-argument-related-changes)
5457

3.0.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ description: Ruby 3.0 full and annotated changelog
88
# Ruby 3.0
99

1010
* **Released at:** Dec 25, 2020 (<a class="github" href="https://github.com/ruby/ruby/blob/ruby_3_0/NEWS.md">NEWS.md</a> file)
11-
* **Status (as of Jul 09, 2022):** 3.0.4 is current _stable_
11+
* **Status (as of Feb 04, 2023):** 3.0.5 is current _stable_
1212
* **This document first published:** Dec 25, 2020
13-
* **Last change to this document:** Jul 09, 2022
13+
* **Last change to this document:** Feb 04, 2023
1414

1515
## Highlights[](#highlights)
1616

@@ -76,6 +76,7 @@ Just a leftover from the separation of keyword arguments.
7676
# Ruby 3.0:
7777
# args=[1, 2, {:a=>true}], kwargs={} -- no attempt to extract hash into keywords, and no error/warning
7878
```
79+
* **Follow-up:** In Ruby 3.2, one more proc argument splatting behavior [was improved](3.2.html#keyword-argument-separation-leftovers).
7980

8081
### Arguments forwarding (`...`) supports leading arguments[](#arguments-forwarding--supports-leading-arguments)
8182

@@ -126,6 +127,9 @@ Just a leftover from the separation of keyword arguments.
126127

127128
delegates(5)
128129
```
130+
* **Follow-ups:**
131+
* In Ruby 3.1, a separate anonymous block argument (bare `&`) forwarding [was added](3.1.html#anonymous-block-argument);
132+
* In Ruby 3.2, separate positional and keyword (bare `*` and `**`) forwarding [were added](3.2.html#anonymous-arguments-passing-improvements).
129133

130134
### "Endless" method definition[](#endless-method-definition)
131135

@@ -357,6 +361,7 @@ Pattern matching now supports "find patterns", with several splats in them.
357361
```
358362
* **Notes:**
359363
* Feature is marked as EXPERIMENTAL, will warn so on an attempt of usage, and may change in the future.
364+
* **Follow-ups:** Feature considered not experimental since 3.2
360365

361366
### Changes in class variable behavior[](#changes-in-class-variable-behavior)
362367

@@ -1030,6 +1035,7 @@ The method will return true for separate Proc instances if the procs were create
10301035
```
10311036
* **Notes:**
10321037
* See [Ractors](#ractors) explanation below, and <a class="ruby-doc" href="https://docs.ruby-lang.org/en/3.0.0/Ractor.html"><code>Ractor</code></a> class docs for deeper understanding of ractors data sharing model.
1038+
* **Follow-up:** In 3.2, the constant was [removed](3.2.html#removals).
10331039

10341040
### Filesystem and IO[](#filesystem-and-io)
10351041

@@ -1127,7 +1133,9 @@ The improvement of inter-thread concurrency for IO-heavy tasks is achieved with
11271133
of blocking the whole thread, they were transferring control while waiting, and all three waits are
11281134
performed in parallel.
11291135
* **Notes:** The feature is somewhat unprecedented for Ruby in the fact that **no default Scheduler implementation** is provided. Implementing the Scheduler in a reliable way (probably using some additional non-blocking event loop library) is completely up to the user. Considering that the feature is implemented by [Samuel Williams](https://github.com/ioquatix) of the <a class="github" href="https://github.com/socketry/async">Async</a> fame, the Async gem <a class="github" href="https://github.com/socketry/async/blob/master/lib/async/scheduler.rb">utilizes</a> the new feature since the day of 3.0 release.
1130-
* **Follow-up:** In Ruby 3.1, [more scheduler hooks were added](3.1.html#fiber-scheduler-new-hooks) to make more core methods support asynchronous execution.
1136+
* **Follow-up:s**
1137+
* In Ruby 3.1, [more scheduler hooks were added](3.1.html#fiber-scheduler-new-hooks) to make more core methods support asynchronous execution;
1138+
* In 3.2, [even more](3.2.html#fiberschedulerio_select) hooks were added, and `SchedulerInteface` documentation abstraction was renamed to `Scheduler`.
11311139

11321140
#### `Thread.ignore_deadlock` accessor[](#threadignore_deadlock-accessor)
11331141

3.1.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
---
22
title: Ruby 3.1 changes
3-
prev: /
4-
next: 3.0
3+
prev: 3.2
4+
next: 3.1
55
description: Ruby 3.1 full and annotated changelog
66
---
77

88
# Ruby 3.1
99

1010
* **Released at:** Dec 25, 2021 (<a class="github" href="https://github.com/ruby/ruby/blob/ruby_3_1/NEWS.md">NEWS.md</a> file)
11-
* **Status (as of Jul 09, 2022):** 3.1.2 is current _stable_
11+
* **Status (as of Feb 04, 2023):** 3.1.3 is current _stable_
1212
* **This document first published:** Jan 5, 2022
13-
* **Last change to this document:** Jul 09, 2022
13+
* **Last change to this document:** Feb 04, 2023
1414

1515
> **Note:** As already explained in [Introduction](README.md), this site is dedicated to changes in the **language**, not the **implementation**, therefore the list below lacks mentions of lots of important optimization introduced in 3.1, including a new JIT named YJIT. That's not because they are not important, just because this site's goals are different.
1616
@@ -106,7 +106,7 @@ In hash literals and method calls, `x:` is now a shortcut for `x: x`—take hash
106106
107107
If method uses its block argument only to pass to another method, it can be marked by anonymous `&`.
108108
109-
* **Reason:** The initial proposal for the feature is 6-year old and focused on avoiding intermediate blocks object allocation on block forwarding. It was considered redundant when block forwarding was optimized in Ruby 2.5; but then the core team decided it is actually a nice and unambiguous shortcut for methods that just pass the block further. As bloc argument is frequently called just `block`, the absence of the name doesn't affect readability.
109+
* **Reason:** The initial proposal for the feature is 6-year old and focused on avoiding intermediate blocks object allocation on block forwarding. It was considered redundant when block forwarding was optimized in Ruby 2.5; but then the core team decided it is actually a nice and unambiguous shortcut for methods that just pass the block further. As block argument is frequently called just `block`, the absence of the name doesn't affect readability.
110110
* **Discussion:** <a class="tracker feature" href="https://bugs.ruby-lang.org/issues/11256">Feature #11256</a>
111111
* **Documentation:** <a class="ruby-doc" href="https://docs.ruby-lang.org/en/3.1/syntax/methods_rdoc.html#label-Block+Argument">doc/syntax/methods.rdoc#Block Argument</a>
112112
* **Code:**
@@ -333,6 +333,7 @@ The class of the context (`self`) available inside the `refine SomeClass do ...
333333
end
334334
end
335335
```
336+
* **Follow-ups:** In Ruby 3.2, several usability improvments using the new class [were introduced](3.2.html#refinements): ability to ask which refinements some module defines, which refinements are active in the current context, and what class or module the particular refinement refines.
336337

337338
#### `Module#prepend` behavior change[](#moduleprepend-behavior-change)
338339

@@ -442,6 +443,7 @@ Now, when module is prepended to the class, it always becomes first in the ances
442443
# => true
443444
```
444445
* **Notes:** Another idea discussed was just having `Method#visibility`, but it was hard to decide on the method's name and what it should return, while three predicates are more or less obvious.
446+
* **Follow-up:** [Reverted](3.2.html#methodpublic-protected-and-private-are-removed) in Ruby 3.2: it was considered after all that visibility is not a property of the method, but rather the responsibility of its owner.
445447

446448
### `Kernel#load`: module as a second argument[](#kernelload-module-as-a-second-argument)
447449

@@ -729,6 +731,7 @@ The new parameter is accepting offsets or timezone objects, and (finally!) allow
729731
#=> #<struct Locale lang=:ua, translations={:user=>"користувач", :application=>"застосунок"}>
730732
# ...no braces necessary, no warning
731733
```
734+
* **Follow-up:** Since 3.2, following the warning, the structs [can be initialized](3.2.html#struct-can-be-initialized-by-keyword-arguments-by-default) by both keyword and positional argument when `keyword_init: true` is not defined.
732735

733736
#### `StructClass#keyword_init?`[](#structclasskeyword_init)
734737

@@ -895,8 +898,6 @@ A new class representing low-level I/O abstraction. Internally, uses OS mechanis
895898
* **Discussion:** <a class="tracker feature" href="https://bugs.ruby-lang.org/issues/18020">Feature #18020</a>
896899
* **Documentation:** <a class="ruby-doc" href="https://docs.ruby-lang.org/en/3.1/IO/Buffer.html"><code>IO::Buffer</code></a>
897900
* **Code:** _This is a big new class, see class' docs for detailed examples of usage, they are quite succinct._
898-
* **Notes:**
899-
* **Follow-up:**
900901

901902
### `File.dirname`: optional `level` to go up the directory tree[](#filedirname-optional-level-to-go-up-the-directory-tree)
902903

0 commit comments

Comments
 (0)