Skip to content

Commit af67d46

Browse files
authored
Merge pull request #2561 from ruby/format-3-0-0-preview2
Adjust markdown format for jekyll
2 parents d1971d3 + e6f4832 commit af67d46

File tree

2 files changed

+152
-47
lines changed

2 files changed

+152
-47
lines changed

en/news/_posts/2020-12-08-ruby-3-0-0-preview2-released.md

Lines changed: 71 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,26 @@ translator:
66
date: 2020-12-08 00:00:00 +0000
77
lang: en
88
---
9+
910
We are pleased to announce the release of Ruby 3.0.0-preview2.
11+
1012
It introduces a number of new features and performance improvements.
13+
1114
## Static Analysis
15+
1216
### RBS
17+
1318
RBS is a language to describe the types of Ruby programs.
19+
1420
Type checkers including TypeProf and other tools supporting RBS will understand Ruby programs much better with RBS definitions.
21+
1522
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+
1624
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+
1726
Ruby 3.0 ships with `rbs` gem, which allows parsing and processing type definitions written in RBS.
1827
The following is a small example of RBS with class, module, and constant definitions.
28+
1929
``` rbs
2030
module ChatApp
2131
VERSION: String
@@ -29,13 +39,21 @@ module ChatApp
2939
end
3040
end
3141
```
42+
3243
See [README of rbs gem](https://github.com/ruby/rbs) for more detail.
44+
3345
### TypeProf
46+
3447
TypeProf is a type analysis tool bundled in the Ruby package.
48+
3549
Currently, TypeProf serves as a kind of type inference.
50+
3651
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.
52+
3753
Here is a simple demo of TypeProf.
54+
3855
An example input:
56+
3957
``` ruby
4058
# test.rb
4159
class User
@@ -46,7 +64,9 @@ class User
4664
end
4765
User.new(name: "John", age: 20)
4866
```
67+
4968
An example output:
69+
5070
```
5171
$ typeprof test.rb
5272
# Classes
@@ -56,16 +76,26 @@ class User
5676
def initialize : (name: String, age: Integer) -> [String, Integer]
5777
end
5878
```
79+
5980
You can run TypeProf by saving the input as "test.rb" and invoke a command called "typeprof test.rb".
81+
6082
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+
6184
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+
6286
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+
6388
## Ractor (experimental)
6489
Ractor is an Actor-model like concurrent abstraction designed to provide a parallel execution feature without thread-safety concerns.
90+
6591
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+
6693
To limit sharing of objects, Ractor introduces several restrictions to the Ruby's syntax (without multiple Ractors, there is no restriction).
94+
6795
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+
6897
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+
6999
``` ruby
70100
require 'prime'
71101
# n.prime? with sent integers in r1, r2 run in parallel
@@ -82,10 +112,15 @@ r2.send 2**61 + 15
82112
p r1.take #=> true
83113
p r2.take #=> true
84114
```
115+
85116
See [doc/ractor.md](https://github.com/ruby/ruby/blob/master/doc/ractor.md) for more details.
117+
86118
## Fiber Scheduler
119+
87120
`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+
88122
Currently supported classes/methods:
123+
89124
- `Mutex#lock`, `Mutex#unlock`, `Mutex#sleep`
90125
- `ConditionVariable#wait`
91126
- `Queue#pop`, `SizedQueue#push`
@@ -98,6 +133,7 @@ Currently supported classes/methods:
98133
(Explain this:)
99134
1. async is outer gem
100135
2. async uses this new feature
136+
101137
``` ruby
102138
require 'async'
103139
require 'net/http'
@@ -110,7 +146,9 @@ Async do
110146
end
111147
end
112148
```
149+
113150
## Other Notable New Features
151+
114152
* One-line pattern matching now uses `=>` instead of `in`.
115153
``` ruby
116154
# version 3.0
@@ -131,30 +169,34 @@ end
131169
end
132170
```
133171
* Endless method definition is added.
134-
``` ruby
135-
def square(x) = x * x
136-
```
172+
``` ruby
173+
def square(x) = x * x
174+
```
137175
* 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+
```
147185
* `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+
```
152190
* Memory view is added as an experimental feature
153191
* This is a new C-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+
154193
## Performance improvements
194+
155195
* Many improvements were implemented in MJIT. See NEWS in detail.
156196
* 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+
157198
## Other notable changes since 2.7
199+
158200
* Keyword arguments are separated from other arguments.
159201
* 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.
160202
* By the way, arguments forwarding now supports leading arguments.
@@ -203,30 +245,43 @@ end
203245
* tmpdir
204246
* tsort
205247
* weakref
248+
206249
See [NEWS](https://github.com/ruby/ruby/blob/v3_0_0_preview2/NEWS.md)
207250
or [commit logs](https://github.com/ruby/ruby/compare/v2_7_0...v3_0_0_preview2)
208251
for more details.
252+
209253
{% assign release = site.data.releases | where: "version", "3.0.0-preview2" | first %}
254+
210255
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)
211256
since Ruby 2.7.0!
257+
212258
Please try Ruby 3.0.0-preview2, and give us any feedback!
259+
213260
## Download
261+
214262
* <{{ release.url.gz }}>
263+
215264
SIZE: {{ release.size.gz }}
216265
SHA1: {{ release.sha1.gz }}
217266
SHA256: {{ release.sha256.gz }}
218267
SHA512: {{ release.sha512.gz }}
268+
219269
* <{{ release.url.xz }}>
270+
220271
SIZE: {{ release.size.xz }}
221272
SHA1: {{ release.sha1.xz }}
222273
SHA256: {{ release.sha256.xz }}
223274
SHA512: {{ release.sha512.xz }}
275+
224276
* <{{ release.url.zip }}>
277+
225278
SIZE: {{ release.size.zip }}
226279
SHA1: {{ release.sha1.zip }}
227280
SHA256: {{ release.sha256.zip }}
228281
SHA512: {{ release.sha512.zip }}
282+
229283
## What is Ruby
284+
230285
Ruby was first developed by Matz (Yukihiro Matsumoto) in 1993,
231286
and is now developed as Open Source. It runs on multiple platforms
232287
and is used all over the world especially for web development.

0 commit comments

Comments
 (0)