Ruby 2.7.0-preview1 Released

We are pleased to announce the release of Ruby 2.7.0-preview1.

A preview version is released to gather feedback for the final release planned to release on December. It introduces a number of new features and performance improvements, most notably:

  • Compaction GC
  • Pattern Matching
  • REPL improvement

Compaction GC

This release introduces Compaction GC which can defragment a fragmented memory space.

Some multithread Ruby programs may cause memory fragmentation, leading to high memory usage and degraded speed.

The GC.compact method is introduced for compacting the heap. This function compacts live objects in the heap so that fewer pages may be used, and the heap may be more CoW friendly. #15626

Pattern Matching [Experimental]

Pattern matching, widely used feature in functional programming languages, is introduced as an experimental feature. #14912 It can traverse a given object and assign its value if it matches a pattern.

case JSON.parse('{...}', symbolize_names: true)
in {name: "Alice", children: [{name: "Bob", age: age}]}
  p age
  ...
end

For more details, please see Pattern matching - New feature in Ruby 2.7.

REPL improvement

irb, bundled interactive environment (REPL; Read-Eval-Print-Loop), now supports multi-line editing. It’s powered by reline, readline compatible pure Ruby implementation. It also provides rdoc integration. In irb you can display the reference for a given class, module, or method. #14683, #14787, #14918 Besides, source lines shown at binding.irb and inspect results for core-class objects are now colorized.

Other Notable New Features

  • A method reference operator, .:, is introduced as an experimental feature. #12125, #13581

  • Numbered parameter as the default block parameter is introduced as an experimental feature. #4475

  • A beginless range is experimentally introduced. It might not be as useful as an endless range, but would be good for DSL purpose. #14799

    ary[..3]  # identical to ary[0..3]
    rel.where(sales: ..100)
    
  • Enumerable#tally is added. It counts the occurrence of each element.

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

Performance improvements

  • JIT [Experimental]

    • JIT-ed code is recompiled to less-optimized code when an optimization assumption is invalidated.

    • Method inlining is performed when a method is considered as pure. This optimization is still experimental and many methods are NOT considered as pure yet.

    • Default value of --jit-min-calls is changed from 5 to 10,000

    • Default value of --jit-max-cache is changed from 1,000 to 100

Other notable changes since 2.6

See NEWS or commit logs for more details.

With those changes, 1727 files changed, 76022 insertions(+), 60286 deletions(-) since Ruby 2.6.0!

Enjoy programming with Ruby 2.7!

Download

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.