Skip to content

Adjust markdown format for jekyll #2561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 71 additions & 16 deletions en/news/_posts/2020-12-08-ruby-3-0-0-preview2-released.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,26 @@ translator:
date: 2020-12-08 00:00:00 +0000
lang: en
---

We are pleased to announce the release of Ruby 3.0.0-preview2.

It introduces a number of new features and performance improvements.

## Static Analysis

### RBS

RBS is a language to describe the types of Ruby programs.

Type checkers including TypeProf and other tools supporting RBS will understand Ruby programs much better with RBS definitions.

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.

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_.

Ruby 3.0 ships with `rbs` gem, which allows parsing and processing type definitions written in RBS.
The following is a small example of RBS with class, module, and constant definitions.

``` rbs
module ChatApp
VERSION: String
Expand All @@ -29,13 +39,21 @@ module ChatApp
end
end
```

See [README of rbs gem](https://github.com/ruby/rbs) for more detail.

### TypeProf

TypeProf is a type analysis tool bundled in the Ruby package.

Currently, TypeProf serves as a kind of type inference.

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.

Here is a simple demo of TypeProf.

An example input:

``` ruby
# test.rb
class User
Expand All @@ -46,7 +64,9 @@ class User
end
User.new(name: "John", age: 20)
```

An example output:

```
$ typeprof test.rb
# Classes
Expand All @@ -56,16 +76,26 @@ class User
def initialize : (name: String, age: Integer) -> [String, Integer]
end
```

You can run TypeProf by saving the input as "test.rb" and invoke a command called "typeprof test.rb".

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!)

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.

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.

## Ractor (experimental)
Ractor is an Actor-model like concurrent abstraction designed to provide a parallel execution feature without thread-safety concerns.

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.

To limit sharing of objects, Ractor introduces several restrictions to the Ruby's syntax (without multiple Ractors, there is no restriction).

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`.

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.

``` ruby
require 'prime'
# n.prime? with sent integers in r1, r2 run in parallel
Expand All @@ -82,10 +112,15 @@ r2.send 2**61 + 15
p r1.take #=> true
p r2.take #=> true
```

See [doc/ractor.md](https://github.com/ruby/ruby/blob/master/doc/ractor.md) for more details.

## Fiber Scheduler

`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.

Currently supported classes/methods:

- `Mutex#lock`, `Mutex#unlock`, `Mutex#sleep`
- `ConditionVariable#wait`
- `Queue#pop`, `SizedQueue#push`
Expand All @@ -98,6 +133,7 @@ Currently supported classes/methods:
(Explain this:)
1. async is outer gem
2. async uses this new feature

``` ruby
require 'async'
require 'net/http'
Expand All @@ -110,7 +146,9 @@ Async do
end
end
```

## Other Notable New Features

* One-line pattern matching now uses `=>` instead of `in`.
``` ruby
# version 3.0
Expand All @@ -131,30 +169,34 @@ end
end
```
* Endless method definition is added.
``` ruby
def square(x) = x * x
```
``` ruby
def square(x) = x * x
```
* Find pattern is added.
``` ruby
case ["a", 1, "b", "c", 2, "d", "e", "f", 3]
in [*pre, String => x, String => y, *post]
p pre #=> ["a", 1]
p x #=> "b"
p y #=> "c"
p post #=> [2, "d", "e", "f", 3]
end
```
``` ruby
case ["a", 1, "b", "c", 2, "d", "e", "f", 3]
in [*pre, String => x, String => y, *post]
p pre #=> ["a", 1]
p x #=> "b"
p y #=> "c"
p post #=> [2, "d", "e", "f", 3]
end
```
* `Hash#except` is now built-in.
``` ruby
h = { a: 1, b: 2, c: 3 }
p h.except(:a) #=> {:b=>2, :c=>3}
```
``` ruby
h = { a: 1, b: 2, c: 3 }
p h.except(:a) #=> {:b=>2, :c=>3}
```
* Memory view is added as an experimental feature
* 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.

## Performance improvements

* Many improvements were implemented in MJIT. See NEWS in detail.
* 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.

## Other notable changes since 2.7

* Keyword arguments are separated from other arguments.
* 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.
* By the way, arguments forwarding now supports leading arguments.
Expand Down Expand Up @@ -203,30 +245,43 @@ end
* tmpdir
* tsort
* weakref

See [NEWS](https://github.com/ruby/ruby/blob/v3_0_0_preview2/NEWS.md)
or [commit logs](https://github.com/ruby/ruby/compare/v2_7_0...v3_0_0_preview2)
for more details.

{% assign release = site.data.releases | where: "version", "3.0.0-preview2" | first %}

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)
since Ruby 2.7.0!

Please try Ruby 3.0.0-preview2, and give us any feedback!

## Download

* <{{ release.url.gz }}>

SIZE: {{ release.size.gz }}
SHA1: {{ release.sha1.gz }}
SHA256: {{ release.sha256.gz }}
SHA512: {{ release.sha512.gz }}

* <{{ release.url.xz }}>

SIZE: {{ release.size.xz }}
SHA1: {{ release.sha1.xz }}
SHA256: {{ release.sha256.xz }}
SHA512: {{ release.sha512.xz }}

* <{{ release.url.zip }}>

SIZE: {{ release.size.zip }}
SHA1: {{ release.sha1.zip }}
SHA256: {{ release.sha256.zip }}
SHA512: {{ release.sha512.zip }}

## What is Ruby

Ruby was first developed by Matz (Yukihiro Matsumoto) in 1993,
and is now developed as Open Source. It runs on multiple platforms
and is used all over the world especially for web development.
Loading