Release of the Ruby programming language 2.7.0

After a year of development published Release Ruby 2.7.0, a dynamic object-oriented programming language that is highly efficient in program development and incorporates the best features of Perl, Java, Python, Smalltalk, Eiffel, Ada and Lisp. The project code is distributed under the BSD ("2-clause BSDL") and "Ruby" licenses, which refers to the latest version of the GPL license and is fully compatible with GPLv3. Ruby 2.7 is the seventh major release to be produced as part of a planned development process that includes setting aside a year for feature enhancements and a 2-3 month patch release.

All improvements:

  • Experimental support pattern matching (pattern matching) to iterate over the given object and assign a value if there is a pattern match.

    case [0, [1, 2, 3]] in [a, [b, *c]] pa #=> 0
    pb #=> 1
    pc #=> [2, 3] end

    case {a: 0, b: 1}
    in{a:0,x:1}
    :unavailable
    in {a: 0, b: var}
    p var #=> 1
    end

  • The shell of interactive calculations irb (REPL, Read-Eval-Print-Loop) now has the possibility of multi-line editing, implemented using a readline-compatible library linewritten in Ruby. Support for rdoc has been integrated, which allows viewing reference information on specified classes, modules and methods in irb. Colored highlighting of lines with code shown through Binding#irb and results of inspecting base class objects is provided.

    Release of the Ruby programming language 2.7.0

  • Added a compact garbage collector (Compaction GC) that can defragment a region of memory, solving the problems of slow performance and increased memory consumption due to memory fragmentation that occurs during the operation of some multi-threaded Ruby applications. To pack objects on the heap proposed GC.compact method to reduce the number of memory pages used and optimize the heap for operations
    CoW (copy-on-write).

  • Carried out preparing to separate arguments based on position in the list ("def foo(a,b,c)") and keywords ("def foo(key: val)"). Automatic argument conversion based on keywords and position has been deprecated and will not be supported in the Ruby 3.0 branch. In particular, it has been deprecated to use the last argument as keyword parameters, to pass keyword-based arguments as the last hash parameter, and to split the last argument into positional and keyword parameters.

    def foo(key: 42); end; foo({key: 42}) #warned
    def foo(**kw); end; foo({key: 42}) #warned
    def foo(key: 42); end; foo(**{key: 42}) # OK
    def foo(**kw); end; foo(**{key: 42}) # OK

    def foo(h, **kw); end; foo(key: 42) #warned
    def foo(h, key: 42); end; foo(key: 42) #warned
    def foo(h, **kw); end; foo({key: 42}) # OK
    def foo(h, key: 42); end; foo({key: 42}) # OK

    def foo(h={}, key: 42); end; foo("key" => 43, key: 42) #warned
    def foo(h={}, key: 42); end; foo({"key" => 43, key: 42}) # warned
    def foo(h={}, key: 42); end; foo({"key" => 43}, key: 42) # OK

    def foo(opt={}); end; foo( key: 42 ) # OK

    def foo(h, **nil); end; foo(key: 1) # ArgumentError
    def foo(h, **nil); end; foo(**{key: 1}) # ArgumentError
    def foo(h, **nil); end; foo("str" ​​=> 1) # ArgumentError
    def foo(h, **nil); end; foo({key: 1}) # OK
    def foo(h, **nil); end; foo({"str" ​​=> 1}) # OK

    h = {}; def foo(*a) end; foo(**h) # [] h = {}; def foo(a) end; foo(**h) # {} and warning
    h = {}; def foo(*a) end; foo(h) # [{}] h = {}; def foo(a) end; foo(h) # {}

  • Possibility using numbered variable names by default for block parameters.

    [1, 2, 3].each { puts @1 } # like [1, 2, 3].each { |i| puts i }

  • Experimental support for ranges with no initial value.

    ary[..3] # same as ary[0..3] rel.where(sales: ..100)

  • Added Enumerable#tally method that counts how many times each element occurs.

    ["a", "b", "c", "b"].tally
    #=> {"a"=>1, "b"=>2, "c"=>1}

  • Private method call allowed with "self" literal

    deffoo
    end
    private :foo
    self.foo

  • Added Enumerator::Lazy#eager method to generate regular enumeration from lazy (Enumerator::Lazy) enumeration.

    a = %w(foo bar baz)
    e = a.lazy.map {|x| x.upcase }.map {|x| x + "!" }.eager
    p e.class #=> Enumerator
    e.map {|x| x + "?" } #=> [β€œFOO!?”, β€œBAR!?”, β€œBAZ!?”]

  • The development of an experimental JIT compiler has continued, which can significantly improve the performance of applications in the Ruby language. The JIT compiler proposed in Ruby first writes C code to disk, after which it calls an external C compiler to generate machine instructions (GCC, Clang and Microsoft VC ++ are supported). The new version implements a method for inline deployment if necessary, selective application of optimization modes during compilation, the default value of "--jit-min-calls" is increased from 5 to 10000, and "--jit-max-cache" from 1000 to 100 .
  • Improved performance of CGI.escapeHTML, Monitor and MonitorMixin.
  • Module#name, true.to_s, false.to_s, and nil.to_s ensure that a string is returned that is unchanged for the specified object.
  • The size of binary files generated by the RubyVM::InstructionSequence#to_binary method has been reduced;
  • Updated versions of built-in components, including
    Bundler 2.1.2, RubyGems 3.1.2,
    Racc 1.4.15,
    CSV 3.1.2, REXML 3.2.3,
    RSS 0.2.8,
    String Scanner 1.0.3;

  • Libraries moved from base distribution to external gem packages
    CMath (cmath gem),
    Scanf (scanf gem),
    Shell (shell gem)
    Synchronizer (sync gem),
    ThreadsWait (thwait gem),
    E2MM (e2mmap gem).

  • The default stdlib modules are published on rubygems.org:
    benchmark,
    cgi,
    delegate
    getoptlong,
    net pop,
    net smtp,
    open3,
    pstore,
    singleton. Monitor modules not moved to rubygems.org
    observer
    timeouts,
    tracer
    hate,
    yaml, which are only shipped with ruby-core.

  • Building Ruby now requires a C compiler that supports the C99 standard.

Source: opennet.ru

Add a comment