Ruby 2.6 is now under the state of the security maintenance phase, until the end of March of 2022.
After that date, maintenance of Ruby 2.6 will be ended.
We recommend you start planning the migration to newer versions of Ruby, such as 3.0 or 2.7.
A cookie prefix spoofing vulnerability was discovered in CGI::Cookie.parse.
This vulnerability has been assigned the CVE identifier CVE-2021-41819.
We strongly recommend upgrading Ruby.
Details
The old versions of CGI::Cookie.parse applied URL decoding to cookie names.
An attacker could exploit this vulnerability to spoof security prefixes in cookie names, which may be able to trick a vulnerable application.
By this fix, CGI::Cookie.parse no longer decodes cookie names.
Note that this is an incompatibility if cookie names that you are using include non-alphanumeric characters that are URL-encoded.
Please update the cgi gem to version 0.3.1, 0.2,1, and 0.1,1 or later. You can use gem update cgi to update it. If you are using bundler, please add gem "cgi", ">= 0.3.1" to your Gemfile.
Alternatively, please update Ruby to 2.7.5 or 3.0.3.
If you are using Ruby 2.6:
Please update Ruby to 2.6.9. You cannot use gem update cgi for Ruby 2.6 or prior.
Affected versions
ruby 2.6.8 or prior (You can not use gem update cgi for this version.)
cgi gem 0.1.0 or prior (which are bundled versions with Ruby 2.7 series prior to Ruby 2.7.5)
cgi gem 0.2.0 or prior (which are bundled versions with Ruby 3.0 series prior to Ruby 3.0.3)
A buffer overrun vulnerability was discovered in CGI.escape_html.
This vulnerability has been assigned the CVE identifier CVE-2021-41816.
We strongly recommend upgrading Ruby.
Details
A security vulnerability that causes buffer overflow when you pass a very large string (> 700 MB) to CGI.escape_html on a platform where long type takes 4 bytes, typically, Windows.
Please update the cgi gem to version 0.3.1, 0.2,1, and 0.1,1 or later. You can use gem update cgi to update it. If you are using bundler, please add gem "cgi", ">= 0.3.1" to your Gemfile.
Alternatively, please update Ruby to 2.7.5 or 3.0.3.
This issue has been introduced since Ruby 2.7, so the cgi version bundled with Ruby 2.6 is not vulnerable.
Affected versions
cgi gem 0.1.0 or prior (which are bundled versions with Ruby 2.7 series prior to Ruby 2.7.5)
cgi gem 0.2.0 or prior (which are bundled versions with Ruby 3.0 series prior to Ruby 3.0.3)
We have released date gem version 3.2.1, 3.1.2, 3.0.2, and 2.0.1 that include a security fix for a regular expression denial of service vulnerability (ReDoS) on date parsing methods. An attacker can exploit this vulnerability to cause an effective DoS attack.
Details
Date’s parsing methods including Date.parse are using Regexps internally, some of which are vulnerable against regular expression denial of service. Applications and libraries that apply such methods to untrusted input may be affected.
The fix limits the input length up to 128 bytes by default instead of changing the regexps. This is because Date gem uses many Regexps and it is possible that there are still undiscovered vulnerable Regexps. For compatibility, it is allowed to remove the limitation by explicitly passing limit keywords as nil like Date.parse(str, limit: nil), but note that it may take a long time to parse.
Please update the date gem to version 3.2.1, 3.1.2, 3.0.2, and 2.0.1, or later. You can use gem update date to update it. If you are using bundler, please add gem "date", ">= 3.2.1" to your Gemfile.
Affected versions
date gem 2.0.0 or prior (which are bundled versions with Ruby 2.6 series)
date gem 3.0.1 or prior (which are bundled versions with Ruby 2.7 series)
date gem 3.1.1 or prior (which are bundled versions with Ruby 3.0 series)
Recently Shopify contributed many Ruby improvements to speed up their Rails application. YJIT is an important contribution, and aims to improve the performance of Rails applications.
Though MJIT is a method-based JIT compiler and uses an external C compiler, YJIT uses Basic Block Versioning and includes JIT compiler inside it. With Lazy Basic Block Versioning (LBBV) it first compiles the beginning of a method, and incrementally compiles the rest when the type of arguments and variables are dynamically determined. See YJIT: a basic block versioning JIT compiler for CRuby for a detailed introduction.
With this technology, YJIT achieves both fast warmup time and performance improvements on most real-world software, up to 22% on railsbench, 39% on liquid-render.
YJIT is still an experimental feature, and as such, it is disabled by default. If you want to use this, specify the --yjit command-line option to enable YJIT. It is also limited to macOS & Linux on x86-64 platforms for now.
A new debugger debug.gem is bundled. debug.gem is fast debugger implementation and it provides many features like remote debugging, colorful REPL, IDE (VSCode) integration and more. It replaces lib/debug.rb standard library.
error_highlight: Fine-grained error location in backtrace
A built-in gem, error_highlight, has been introduced. It includes fine-grained error location in backtrace:
$ ruby test.rb
test.rb:1:in `<main>': undefined method `time' for 1:Integer (NoMethodError)
1.time {}
^^^^^
Did you mean? times
This gem is enabled by default. You can disable it by using a command-line option --disable-error_highlight. See the repository in detail.
Irb improvement
To be described in next preview.
Other Notable New Features
Language
Values in Hash literals and keyword arguments can be omitted. [Feature #14579]
{x:, y:} is a syntax sugar of {x: x, y: y}.
foo(x:, y:) is a syntax sugar of foo(x: x, y: y).
Pin operator in pattern matching now takes an expression. [Feature #17411]
For workloads like Rails, the default --jit-max-cache is changed from 100 to 10000.
The JIT compiler no longer skips compilation of methods longer than 1000 instructions.
To support Zeitwerk of Rails, JIT-ed code is no longer cancelled
when a TracePoint for class events is enabled.
Other notable changes since 3.0
One-line pattern matching, e.g., ary => [x, y, z], is no longer experimental.
Multiple assignment evaluation order has been changed slightly. [Bug #4443]]
foo[0], bar[0] = baz, qux was evaluated in order baz, qux, foo, and then bar in Ruby 3.0. In Ruby 3.1, it is evaluated in order foo, bar, baz, and then qux.
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.
The Government of Fukuoka, Japan together with “Matz” Matsumoto would like to invite you to enter the following Ruby competition. If you have developed an interesting Ruby program, please be encouraged to apply.
2022 Fukuoka Ruby Award Competition - Grand Prize - 1 Million Yen!
Entry Deadline: December 3, 2021
Matz and a group of panelists will select the winners of the Fukuoka Competition. The grand prize for the Fukuoka Competition is 1 million yen. Past grand prize winners include Rhomobile (USA) and APEC Climate Center (Korea).
Programs entered in the competition do not have to be written entirely in Ruby but should take advantage of the unique characteristics of Ruby.
The program must have been developed or updated in the past year or so. Please visit the following Fukuoka website to enter.
A trusting FTP PASV responses vulnerability was discovered in Net::FTP.
This vulnerability has been assigned the CVE identifier CVE-2021-31810.
We strongly recommend upgrading Ruby.
net-ftp is a default gem in Ruby 3.0.1 but it has a packaging issue, so please upgrade Ruby itself.
Details
A malicious FTP server can use the PASV response to trick Net::FTP
into connecting back to a given IP address and port. This
potentially makes Net::FTP extract information about services that are
otherwise private and not disclosed (e.g., the attacker can conduct port scans
and service banner extractions).
A StartTLS stripping vulnerability was discovered in Net::FTP.
This vulnerability has been assigned the CVE identifier CVE-2021-32066.
We strongly recommend upgrading Ruby.
net-imap is a default gem in Ruby 3.0.1 but it has a packaging issue, so please upgrade Ruby itself.
Details
Net::IMAP does not raise an exception when StartTLS
fails with an unknown response, which might allow man-in-the-middle
attackers to bypass the TLS protections by leveraging a network
position between the client and the registry to block the StartTLS
command, aka a “StartTLS stripping attack.”
We ordinally do not fix Ruby 2.6 except security fixes, but this release also includes some regressed bugs and build problem fixes.
See the commit logs for details.
Ruby 2.6 is now under the state of the security maintenance phase, until the end of March of 2022.
After that date, maintenance of Ruby 2.6 will be ended.
We recommend you start planning the migration to newer versions of Ruby, such as 3.0 or 2.7.
There is a vulnerability about Command Injection in RDoc which is bundled in Ruby.
It is recommended that all Ruby users update RDoc to the latest version that fixes this issue.
RDoc used to call Kernel#open to open a local file. If a Ruby project has a file whose name starts with | and ends with tags, the command following the pipe character is executed. A malicious Ruby project could exploit it to run an arbitrary command execution against a user who attempts to run rdoc command.
Ruby users whose version of RDoc is affected by this issue should update to the latest version of RDoc.
Affected Versions
All releases of RDoc from 3.11 to 6.3.0
How to Update
Run the following command to update RDoc to the latest version (6.3.1 or later) to fix the vulnerability.
There is an XML round-trip vulnerability in REXML gem bundled with Ruby. This vulnerability has been assigned the CVE identifier CVE-2021-28965. We strongly recommend upgrading the REXML gem.
Details
When parsing and serializing a crafted XML document, REXML gem (including the one bundled with Ruby) can create a wrong XML document whose structure is different from the original one. The impact of this issue highly depends on context, but it may lead to a vulnerability in some programs that are using REXML.
Please update REXML gem to version 3.2.5 or later.
If you are using Ruby 2.6 or later:
Please use Ruby 2.6.7, 2.7.3, or 3.0.1.
Alternatively, you can use gem update rexml to update it. If you are using bundler, please add gem "rexml", ">= 3.2.5" to your Gemfile.
If you are using Ruby 2.5.8 or prior:
Please use Ruby 2.5.9.
You cannot use gem update rexml for Ruby 2.5.8 or prior.
Note that Ruby 2.5 series is now EOL, so please consider upgrading Ruby to 2.6.7 or later as soon as possible.
Affected versions
Ruby 2.5.8 or prior (You can NOT use gem upgrade rexml for this version.)
There is an unintentional directory creation vulnerability in tmpdir library bundled with Ruby on Windows. And there is also an unintentional file creation vulnerability in tempfile library bundled with Ruby on Windows, because it uses tmpdir internally. This vulnerability has been assigned the CVE identifier CVE-2021-28966.
Details
Dir.mktmpdir method introduced by tmpdir library accepts the prefix and the suffix of the directory which is created as the first parameter. The prefix can contain relative directory specifiers "..\\", so this method can be used to target any directory. So, if a script accepts an external input as the prefix, and the targeted directory has inappropriate permissions or the ruby process has inappropriate privileges, the attacker can create a directory or a file at any directory.
This is the same issue as CVE-2018-6914, but the previous fix was incomplete on Windows.
All users running an affected release should upgrade immediately.
By this release, we end the normal maintenance phase of Ruby 2.6,
and Ruby 2.6 enters the security maintenance phase.
This means that we will no longer backport any bug fixes to Ruby 2.6 except security fixes.
The term of the security maintenance phase is scheduled for a year.
Ruby 2.6 reaches EOL and its official support ends by the end of the security maintenance phase.
Therefore, we recommend that you start to plan upgrade to Ruby 2.7 or 3.0.
After this release, Ruby 2.5 reaches EOL. In other words, this is the last release of Ruby 2.5 series.
We will not release Ruby 2.5.10 even if a security vulnerability is found.
We recommend all Ruby 2.5 users to upgrade to Ruby 3.0, 2.7 or 2.6 immediately.
We are pleased to announce the release of Ruby . From 2015 we developed hard toward Ruby 3, whose goal is performance, concurrency, and Typing. Especially about performance, Matz stated “Ruby3 will be 3 times faster than Ruby2” a.k.a. Ruby 3x3.
With Optcarrot benchmark, which measures single thread performance based on NES’s game emulation workload, it achieved 3x faster performance than Ruby 2.0! These were measured at the environment written in https://benchmark-driver.github.io/hardware.html. 8c510e4095 was used as Ruby 3.0. It may not be 3x faster depending on your environment or benchmark.
Ruby 3.0.0 covers those goals by
Performance
MJIT
Concurrency
Ractor
Fiber Scheduler
Typing (Static Analysis)
RBS
TypeProf
With above performance improvement Ruby 3.0 introduces a number of new features described below.
Performance
When I first declared “Ruby3x3” in the conference keynote, many including members of the core team felt “Matz is a boaster”. In fact, I felt so too. But we did. I am honored to see the core team actually accomplished to make Ruby3.0 three times faster than Ruby2.0 (in some benchmarks). – Matz
MJIT
Many improvements were implemented in MJIT. See NEWS for details.
As of Ruby 3.0, JIT is supposed to give performance improvements in limited workloads, such as games (Optcarrot), AI (Rubykon), or whatever application that spends majority of time in calling a few methods many times.
Although Ruby 3.0 significantly decreased a size of JIT-ed code, it is still not ready for optimizing workloads like Rails, which often spend time on so many methods and therefore suffer from i-cache misses exacerbated by JIT. Stay tuned for Ruby 3.1 for further improvements on this issue.
Concurrency / Parallel
It’s multi-core age today. Concurrency is very important. With Ractor, along with Async Fiber, Ruby will be a real concurrent language. — Matz
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 exchaning messages.
To limit sharing of objects, Ractor introduces several restrictions to the Ruby’s syntax (without multiple Ractors, there is no restriction).
The specification and implementation 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 measures the execution time of famous benchmark tak function (Tak (function) - Wikipedia), by executing it 4 times sequentially or 4 times in parallel with ractors.
def tarai(x, y, z) =
x <= y ? y : tarai(tarai(x-1, y, z),
tarai(y-1, z, x),
tarai(z-1, x, y))
require 'benchmark'
Benchmark.bm do |x|
# sequential version
x.report('seq'){ 4.times{ tarai(14, 7, 0) } }
# parallel version
x.report('par'){
4.times.map do
Ractor.new { tarai(14, 7, 0) }
end.each(&:take)
}
end
Benchmark result:
user system total real
seq 64.560736 0.001101 64.561837 ( 64.562194)
par 66.422010 0.015999 66.438009 ( 16.685797)
The result was measured on Ubuntu 20.04, Intel(R) Core(TM) i7-6700 (4 cores, 8 hardware threads). It shows that the parallel version is 3.87 times faster than the sequential version.
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” for an overview of how it works.
Currently supported classes/methods:
Mutex#lock, Mutex#unlock, Mutex#sleep
ConditionVariable#wait
Queue#pop, SizedQueue#push
Thread#join
Kernel#sleep
Process.wait
IO#wait, IO#read, IO#write and related methods (e.g. #wait_readable, #gets, #puts and so on).
IO#select is not supported.
This example program will perform several HTTP requests concurrently:
require 'async'
require 'net/http'
require 'uri'
Async do
["ruby", "rails", "async"].each do |topic|
Async do
Net::HTTP.get(URI "https://www.google.com/search?q=#{topic}")
end
end
end
It uses async which provides the event loop. This event loop uses the Fiber#scheduler hooks to make Net::HTTP non-blocking. Other gems can use this interface to provide non-blocking execution for Ruby, and those gems can be compatible with other implementations of Ruby (e.g. JRuby, TruffleRuby) which can support the same non-blocking hooks.
Static Analysis
2010s were an age of statically type programming languages. Ruby seeks the future with static type checking, without type declaration, using abstract interpretation. RBS & TypeProf are the first step to the future. More steps to come. — Matz
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.
module ChatApp
VERSION: String
class Channel
attr_reader name: String
attr_reader messages: Array[Message]
attr_reader users: Array[User | Bot] # `|` means union types, `User` or `Bot`.
def initialize: (String) -> void
def post: (String, from: User | Bot) -> Message # Method overloading is supported.
| (File, from: User | Bot) -> Message
end
end
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:
# test.rb
class User
def initialize(name:, age:)
@name, @age = name, age
end
attr_reader :name, :age
end
User.new(name: "John", age: 20)
An example output:
$ typeprof test.rb
# Classes
class User
attr_reader name : String
attr_reader age : Integer
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. (It runs TypeProf on the server side, so sorry if it is out!)
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.
Other Notable New Features
One-line pattern matching is redesigned. (experimental)
=> is added. It can be used as like rightward assignment.
0 => a
p a #=> 0
{b: 0, c: 1} => {b:}
p b #=> 0
in is changed to return true or false.
# version 3.0
0 in 1 #=> false
# version 2.7
0 in 1 #=> raise NoMatchingPatternError
Find pattern is added. (experimental)
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
Endless method definition is added.
def square(x) = x * x
Hash#except is now built-in.
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
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 goes from 11.7 seconds to 0.22 seconds.
The measure command has been added to IRB. It allows simple execution time measurement.
Keyword arguments are separated from other arguments.
In principle, code that prints a warning on Ruby 2.7 won’t work. See the document in detail.
By the way, arguments forwarding now supports leading arguments.
def method_missing(meth, ...)
send(:"do_#{ meth }", ...)
end
Pattern matching (case/in) is no longer experimental.
The $SAFE feature was completely removed; now it is a normal global variable.
The order of backtrace had been reversed at Ruby 2.5, and is reverted. Now it behaves like Ruby 2.4; an error message and the line number where the exception occurs are printed first, and its callers are printed later.
Some standard libraries are updated.
RubyGems 3.2.3
Bundler 2.2.3
IRB 1.2.6
Reline 0.1.5
Pysch 3.3.0
JSON 2.5.0
BigDecimal 3.0.0
CSV 3.1.9
Date 3.1.1
Digest 3.0.0
Fiddle 1.0.5
StringIO 3.0.0
StringScanner 3.0.0
etc.
The following libraries are no longer bundled gems or standard libraries.
Install the corresponding gems to use these features.
sdbm
webrick
net-telnet
xmlrpc
The following default gems are now bundled gems.
rexml
rss
The following stdlib files are now default gems and are published on rubygems.org.
Ruby3.0 is a milestone. The language is evolved, keeping compatibility. But it’s not the end. Ruby will keep progressing, and become even greater. Stay tuned! — Matz
Merry Christmas, Happy Holidays, and enjoy programming with Ruby 3.0!
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.
We are pleased to announce the release of Ruby 3.0.0-rc1.
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.
module ChatApp
VERSION: String
class Channel
attr_reader name: String
attr_reader messages: Array[Message]
attr_reader users: Array[User | Bot] # `|` means union types, `User` or `Bot`.
def initialize: (String) -> void
def post: (String, from: User | Bot) -> Message # Method overloading is supported.
| (File, from: User | Bot) -> Message
end
end
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:
# test.rb
class User
def initialize(name:, age:)
@name, @age = name, age
end
attr_reader :name, :age
end
User.new(name: "John", age: 20)
An example output:
$ typeprof test.rb
# Classes
class User
attr_reader name : String
attr_reader age : Integer
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. (It runs TypeProf on the server side, so sorry if it is out!)
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 implementation 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 compared to the sequential program on the parallel computer.
require 'prime'
# n.prime? with sent integers in r1, r2 run in parallel
r1, r2 = *(1..2).map do
Ractor.new do
n = Ractor.recv
n.prime?
end
end
# send parameters
r1.send 2**61 - 1
r2.send 2**61 + 15
# wait for the results of expr1, expr2
p r1.take #=> true
p r2.take #=> true
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” for an overview of how it works.
Currently supported classes/methods:
Mutex#lock, Mutex#unlock, Mutex#sleep
ConditionVariable#wait
Queue#pop, SizedQueue#push
Thread#join
Kernel#sleep
Process.wait
IO#wait, IO#read, IO#write and related methods (e.g. #wait_readable, #gets, #puts and so on).
IO#select is not supported.
(Explain Async gem with links). This example program will perform several HTTP requests concurrently:
(Explain this:)
async is outer gem
async uses this new feature
require 'async'
require 'net/http'
require 'uri'
Async do
["ruby", "python", "c"].each do |topic|
Async do
Net::HTTP.get(URI "https://www.google.com/search?q=#{topic}")
end
end
end
Other Notable New Features
One-line pattern matching is redesigned. (experimental)
=> is added. It can be used as like rightward assignment.
0 => a
p a #=> 0
{b: 0, c: 1} => {b:}
p b #=> 0
in is changed to return true or false.
# version 3.0
0 in 1 #=> false
# version 2.7
0 in 1 #=> raise NoMatchingPatternError
Find pattern is added. (experimental)
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
Endless method definition is added.
def square(x) = x * x
Hash#except is now built-in.
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 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 in detail.
By the way, arguments forwarding now supports leading arguments.
def method_missing(meth, ...)
send(:"do_#{ meth }", ...)
end
Pattern matching (case/in) is no longer experimental.
The $SAFE feature was completely removed; now it is a normal global variable.
The order of backtrace had been reversed at Ruby 2.5, and is reverted. Now it behaves like Ruby 2.4; an error message and the line number where the exception occurs are printed first, and its callers are printed later.
Some standard libraries are updated.
RubyGems 3.2.2
Bundler 2.2.2
IRB 1.2.6
Reline 0.1.5
Pysch 3.2.1
JSON 2.4.1
BigDecimal 3.0.0
CSV 3.1.9
Digest 3.0.0
Fiddle 1.0.4
StringIO 3.0.0
StringScanner 3.0.0
The following libraries are no longer bundled gems.
Install the corresponding gems to use these features.
net-telnet
xmlrpc
The following default gems are now bundled gems.
rexml
rss
The following stdlib files are now default gems and are published on rubygems.org.
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.