Paul Krill
Editor at Large

Ruby 2.7 improves garbage collection, pattern matching

news
Jan 6, 20202 mins

Ruby upgrade also includes enhancements to the REPL and an experimental just-in-time compiler

two rubies ruby
Credit: Aleksey Nemiro

Ruby 2.7, the latest upgrade of the Ruby programming language, is now generally available as a production release. The new release brings improvements in garbage collection, pattern matching, and REPL (read-eval-print-loop).

New in the Ruby 2.7 is compaction garbage collection, which is used to defragment a fragmented memory space. The GC.compact method compacts the objects in the heap so that fewer pages are used. Members of the Ruby development team explained that some multi-threaded Ruby programs may cause memory fragmentation, which leads to high memory utilization and speed degradation.

Other improvements in Ruby 2.7.0 include:

  • An experimental pattern matching capability, which can traverse a given object and assign a value if it matches a pattern. Pattern matching is widely used in functional programming languages.
  • Multi-line editing is now supported in irb, the interactive Ruby shell. Integration with rdoc, the Ruby documentation system, also is provided. With irb, developers can display the reference for a class, method, or module. Also, source lines shown at binding.irb and inspect results for core-class objects now are colorized.
  • Automatic conversion of keyword and positional arguments has been deprecated. This feature will be removed in Ruby 3.
  • For the still-experimental just-in-time (JIT) compiler, first introduced in Ruby 2.6, JIT-ed code is recompiled to less-optimized code when an optimization has been invalidated. Further, method inlining is performed when a method is considered pure. However, many methods are not yet considered pure.
  • An Enumerable#tally counts the occurrence of each element.
  • Also introduced is a numbered parameter as the default block parameter.

You can download Ruby 2.7 from ruby-lang.org.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author