Ruby 2.5 Adds Support For Branch Coverage
Written by Kay Ewbank   
Wednesday, 03 January 2018

The first stable release of the Ruby 2.5 series comes with a number of new features and performance improvements, including support for branch coverage and the ability for enumerable predicates to accept pattern arguments.


rubylogo2a

Ruby's massive popularity as a programming language comes partially from the fact that it is fun to use, and useful because of its mix of different programming styles - functional, dynamic and object-oriented. 

The new features of this first release of the Ruby 2.5 line start with the support for branch coverage and method coverage as new target types of coverage for the coverage measurement library. The branch coverage indicates which branches are executed and which are not. The method coverage indicates which methods are invoked and which are not. By running a test suite with these new features, you will know which branches and methods are executed, and evaluate total coverage of the test suite more strictly.

Another improvement to the language is the ability to pass pattern arguments to enumerable predicates. Ruby has sequence predicates such as all? none?, one? and any?, all of which take a block and evaluate it by passing every element of the sequence to it.

Ruby 2.5 now supports passing a pattern argument. This returns, in the case of a single argument, whether the block'squery holds when each element is supplied to the argument's #=== method. The feature is based on how Enumerable#grep works. If grep is given a regular expression as an argument, it returns an array containing the items in the original array that match the given regular expression.

Other improvements to Ruby 2.5 include the ability to use rescue/else/ensure directly with do/end blocks, avoiding the need for additional statements when wanting to get out of the block in case of an error. Yield_self has been added as an option to yield. It yields the receiver to the given block and returns the result of the block. Hash#slice and Hash#transform_keys have been added, and Struct.new can create classes that accept keyword arguments.

The performance of the new release has been improved by between five and ten percent by removing all trace instructions from the overall bytecode (instruction sequences). The developers say that trace was added to support the TracePoint, but isn't used in the majority of cases, so the trace instructions represent an overhead. Where the facility is needed, the new version uses a dynamic instrumentation technique.

Other performance improvements see block passing by a block parameter running around three times faster than Ruby 2.4 by use of the “Lazy Proc allocation” technique; and Mutex has been rewritten to be smaller and faster.

The new release is available for download.

 rubylogo2a

 

More Information

Ruby Official Site

Related Articles

Commercial Ruby Distro Enters Beta

Ruby On Rails Reaches 5.0

Ruby 2.3 Released

ActiveState Extends to Ruby, Node.js, Go and Lua

 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

 

Banner


OSI Updates Open Source AI Definition
06/09/2024

A new version of the Open Source AI Definition has been released by the Open Source Initiative. The update is part of the drive to have a stable release of the definition ready by the end of October 2 [ ... ]



Does AI Help or Hinder?
02/10/2024

After early indications that AI-powered coding assistants increase developer productivity, findings are emerging that challenge this and suggest code quality may be reduced by their use. At the same t [ ... ]


More News

 

kotlin book

 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Thursday, 08 March 2018 )