Image source
Good news for developers -Ruby 3.0.0is out, a new release of a dynamic object-oriented programming language. According to his fans, the new version includes the best from Perl, Java, Python, Smalltalk, Eiffel, Ada and Lisp.
The new version of Ruby is the eighth major release and has received many updates and improvements. By the way, the developers have been working on the third version for about five years. Its features are high performance, concurrency and typing.
By the way, the same five years ago, the author of the language Yukihiro Matsumoto proposed the Ruby 3x3 concept. It implies that the release of Ruby 3.0 will become possible after three times the performance improvement over version 2.0 can be achieved. In the latest release, this has been achieved through improved JIT compilation support.
What's new?
- RBS, Ruby. RBS . : , , , . , TypeProf, , RBS.
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
- Ractor. , . , , . .
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- Fiber#scheduler, , . , :
- 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 with them methods
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
- The one-liners of pattern matching "Add operator - value-variable", which is used for right-hand assignment of values, have been redesigned.
0 => a
p a #=> 0
{b: 0, c: 1} => {b:}
p b #=> 0
In addition, the behavior of "in" has been changed, it now returns true or false.
# version 3.0
0 in 1 #=> false
# version 2.7
0 in 1 #=> raise NoMatchingPatternError
Added experimental template for finding values:
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
- Added Hash # except method.
h = { a: 1, b: 2, c: 3 }
p h.except(:a) #=> {:b=>2, :c=>3}
- There is now support for one-line method definitions without using the "end" keyword.
def square(x) = x * x
- C-API - .
- IRB. , 53 (!) , Ruby 2.7.
- gem-, stdlib.