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.


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 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.



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.



nginx Core Developer Announces New Fork

One of the core developers of nginx has said he is no longer working on the development of the popular and widely used nginx web server, and is instead working on a new fork. Maxim Dounin release [ ... ]

JetBrains Announces Academy AI Festival

JetBrains is running an Academy AI Festival that they describe as a fusion of hands-on learning and inspiring challenges that will provide inspiration for innovation and will advance your understandin [ ... ]

More News


raspberry pi books



or email your comment to:

Last Updated ( Thursday, 08 March 2018 )