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


Couchbase's Coding Assistant Goes GA
11/03/2024

Capella iQ, the AI coding assistant for developers that makes interacting with Couchbase using natural language possible, has gone from private beta to being generally available.



Pi Day - The Great Unanswered Questions
14/03/2024

It's Pi day again, again, again... Even after so many, I still have things to say about this most intriguing number. The most important things about Pi is that it is irrational and one of the few tran [ ... ]


More News

 

raspberry pi books

 

Comments




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

Last Updated ( Thursday, 08 March 2018 )