You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: en/news/_posts/2020-12-08-ruby-3-0-0-preview2-released.md
+71-16Lines changed: 71 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -6,16 +6,26 @@ translator:
6
6
date: 2020-12-08 00:00:00 +0000
7
7
lang: en
8
8
---
9
+
9
10
We are pleased to announce the release of Ruby 3.0.0-preview2.
11
+
10
12
It introduces a number of new features and performance improvements.
13
+
11
14
## Static Analysis
15
+
12
16
### RBS
17
+
13
18
RBS is a language to describe the types of Ruby programs.
19
+
14
20
Type checkers including TypeProf and other tools supporting RBS will understand Ruby programs much better with RBS definitions.
21
+
15
22
You can write down the definition of classes and modules: methods defined in the class, instance variables and their types, and inheritance/mix-in relations.
23
+
16
24
The goal of RBS is to support commonly seen patterns in Ruby programs and it allows writing advanced types including union types, method overloading, and generics. It also supports duck typing with _interface types_.
25
+
17
26
Ruby 3.0 ships with `rbs` gem, which allows parsing and processing type definitions written in RBS.
18
27
The following is a small example of RBS with class, module, and constant definitions.
28
+
19
29
```rbs
20
30
module ChatApp
21
31
VERSION: String
@@ -29,13 +39,21 @@ module ChatApp
29
39
end
30
40
end
31
41
```
42
+
32
43
See [README of rbs gem](https://github.com/ruby/rbs) for more detail.
44
+
33
45
### TypeProf
46
+
34
47
TypeProf is a type analysis tool bundled in the Ruby package.
48
+
35
49
Currently, TypeProf serves as a kind of type inference.
50
+
36
51
It reads plain (non-type-annotated) Ruby code, analyzes what methods are defined and how they are used, and generates a prototype of type signature in RBS format.
You can run TypeProf by saving the input as "test.rb" and invoke a command called "typeprof test.rb".
81
+
60
82
You can also [try TypeProf online](https://mame.github.io/typeprof-playground/#rb=%23+test.rb%0Aclass+User%0A++def+initialize%28name%3A%2C+age%3A%29%0A++++%40name%2C+%40age+%3D+name%2C+age%0A++end%0A++%0A++attr_reader+%3Aname%2C+%3Aage%0Aend%0A%0AUser.new%28name%3A+%22John%22%2C+age%3A+20%29&rbs=). (It runs TypeProf on the server side, so sorry if it is out!)
83
+
61
84
See [the documentation](https://github.com/ruby/typeprof/blob/master/doc/doc.md) and [demos](https://github.com/ruby/typeprof/blob/master/doc/demo.md) for details.
85
+
62
86
TypeProf is experimental and not so mature yet; only a subset of the Ruby language is supported, and the detection of type errors is limited. But it is still growing rapidly to improve the coverage of language features, the analysis performance, and usability. Any feedback is very welcome.
87
+
63
88
## Ractor (experimental)
64
89
Ractor is an Actor-model like concurrent abstraction designed to provide a parallel execution feature without thread-safety concerns.
90
+
65
91
You can make multiple ractors and you can run them in parallel. Ractor enables you to make thread-safe parallel programs because ractors can not share normal objects. Communication between ractors are supported by message passing.
92
+
66
93
To limit sharing of objects, Ractor introduces several restrictions to the Ruby's syntax (without multiple Ractors, there is no restriction).
94
+
67
95
The specification and implmentation are not matured and may be changed in the future, so this feature is marked as experimental and show the "experimental feature" warning when the first `Ractor.new`.
96
+
68
97
The following small program calculates `n.prime?` (`n` is relatively a big integer) in parallel with two ractors. You will confirm that the program execution is about x2 times faster ompare with the sequential program on the parallel computer.
98
+
69
99
```ruby
70
100
require'prime'
71
101
# n.prime? with sent integers in r1, r2 run in parallel
@@ -82,10 +112,15 @@ r2.send 2**61 + 15
82
112
p r1.take #=> true
83
113
p r2.take #=> true
84
114
```
115
+
85
116
See [doc/ractor.md](https://github.com/ruby/ruby/blob/master/doc/ractor.md) for more details.
117
+
86
118
## Fiber Scheduler
119
+
87
120
`Fiber#scheduler` is introduced for intercepting blocking operations. This allows for light-weight concurrency without changing existing code. Watch ["Don't Wait For Me, Scalable Concurrency for Ruby 3"](https://www.youtube.com/watch?v=Y29SSOS4UOc) for an overview of how it works.
121
+
88
122
Currently supported classes/methods:
123
+
89
124
-`Mutex#lock`, `Mutex#unlock`, `Mutex#sleep`
90
125
-`ConditionVariable#wait`
91
126
-`Queue#pop`, `SizedQueue#push`
@@ -98,6 +133,7 @@ Currently supported classes/methods:
98
133
(Explain this:)
99
134
1. async is outer gem
100
135
2. async uses this new feature
136
+
101
137
```ruby
102
138
require'async'
103
139
require'net/http'
@@ -110,7 +146,9 @@ Async do
110
146
end
111
147
end
112
148
```
149
+
113
150
## Other Notable New Features
151
+
114
152
* One-line pattern matching now uses `=>` instead of `in`.
115
153
```ruby
116
154
# version 3.0
@@ -131,30 +169,34 @@ end
131
169
end
132
170
```
133
171
*Endless method definition is added.
134
-
``` ruby
135
-
def square(x) = x * x
136
-
```
172
+
``` ruby
173
+
def square(x) = x * x
174
+
```
137
175
*Find pattern is added.
138
-
``` ruby
139
-
case ["a", 1, "b", "c", 2, "d", "e", "f", 3]
140
-
in [*pre, String => x, String => y, *post]
141
-
p pre #=> ["a", 1]
142
-
p x #=> "b"
143
-
p y #=> "c"
144
-
p post #=> [2, "d", "e", "f", 3]
145
-
end
146
-
```
176
+
``` ruby
177
+
case ["a", 1, "b", "c", 2, "d", "e", "f", 3]
178
+
in [*pre, String => x, String => y, *post]
179
+
p pre #=> ["a", 1]
180
+
p x #=> "b"
181
+
p y #=> "c"
182
+
p post #=> [2, "d", "e", "f", 3]
183
+
end
184
+
```
147
185
*`Hash#except` is now built-in.
148
-
``` ruby
149
-
h = { a: 1, b: 2, c: 3 }
150
-
p h.except(:a) #=> {:b=>2, :c=>3}
151
-
```
186
+
``` ruby
187
+
h = { a: 1, b: 2, c: 3 }
188
+
p h.except(:a) #=> {:b=>2, :c=>3}
189
+
```
152
190
*Memory view is added as an experimental feature
153
191
*This is a newC-API set to exchange a raw memory area, such as a numeric array and a bitmap image, between extension libraries. The extension libraries can share also the metadata of the memory area that consists of the shape, the element format, and so on. Using these kinds of metadata, the extension libraries can share even a multidimensional array appropriately. This feature is designed by referring to Python's buffer protocol.
192
+
154
193
## Performance improvements
194
+
155
195
* Many improvements were implemented in MJIT. See NEWS in detail.
156
196
* Pasting long code to IRB is 53 times faster than bundled with Ruby 2.7.0. For example, the time required to paste [this sample code](https://gist.github.com/aycabta/30ab96334275bced5796f118c9220b0b) goes from 11.7 seconds to 0.22 seconds.
197
+
157
198
## Other notable changes since 2.7
199
+
158
200
* Keyword arguments are separated from other arguments.
159
201
* In principle, code that prints a warning on Ruby 2.7 won't work. See the [document](https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/) in detail.
160
202
*By the way, arguments forwarding now supports leading arguments.
@@ -203,30 +245,43 @@ end
203
245
* tmpdir
204
246
* tsort
205
247
* weakref
248
+
206
249
See [NEWS](https://github.com/ruby/ruby/blob/v3_0_0_preview2/NEWS.md)
207
250
or [commit logs](https://github.com/ruby/ruby/compare/v2_7_0...v3_0_0_preview2)
208
251
for more details.
252
+
209
253
{% assign release = site.data.releases |where:"version", "3.0.0-preview2"| first %}
254
+
210
255
With those changes, [{{ release.stats.files_changed }} files changed, {{ release.stats.insertions }} insertions(+), {{ release.stats.deletions }} deletions(-)](https://github.com/ruby/ruby/compare/v2_7_0...v3_0_0)
211
256
since Ruby2.7.0!
257
+
212
258
Please try Ruby3.0.0-preview2, and give us any feedback!
259
+
213
260
## Download
261
+
214
262
*<{{ release.url.gz }}>
263
+
215
264
SIZE: {{ release.size.gz }}
216
265
SHA1: {{ release.sha1.gz }}
217
266
SHA256: {{ release.sha256.gz }}
218
267
SHA512: {{ release.sha512.gz }}
268
+
219
269
*<{{ release.url.xz }}>
270
+
220
271
SIZE: {{ release.size.xz }}
221
272
SHA1: {{ release.sha1.xz }}
222
273
SHA256: {{ release.sha256.xz }}
223
274
SHA512: {{ release.sha512.xz }}
275
+
224
276
*<{{ release.url.zip }}>
277
+
225
278
SIZE: {{ release.size.zip }}
226
279
SHA1: {{ release.sha1.zip }}
227
280
SHA256: {{ release.sha256.zip }}
228
281
SHA512: {{ release.sha512.zip }}
282
+
229
283
## What is Ruby
284
+
230
285
Ruby was first developed by Matz (YukihiroMatsumoto) in1993,
231
286
and is now developed as OpenSource. It runs on multiple platforms
232
287
and is used all over the world especially for web development.
0 commit comments