Ruby 2.6 – an exciting Christmas present - Questers

Ruby 2.6 – an exciting Christmas present

Ruby is a dynamic, object-oriented programming language which has remained a top trend in recent years. Along with its web app framework Rails, it is widely used in a number of well-known projects such as Airbnb, Dribbble, Goodreads as well as one of Questers’ partners Funding Circle – a leading peer-to-peer lending marketplace.

Since the release of Ruby 2.1 on December 25, 2013, the development cycles went on and now the community is eager to see what the upcoming 2.6 version will bring for Christmas. The announced on December 6 first release candidate Ruby 2.6.0-rc1, came with some exciting new features and performance improvements. And although it may spoil the Christmas surprise for some, let’s take a look at them.

JIT compiler

Ruby 2.6 will introduce an initial implementation of a JIT (Just-in-Time) compiler. Its main goal is to improve the performance of any Ruby program execution by providing a unique way of “inspecting” the code. Ruby’s JIT compiler generates common C compiler process to create native code.

As stated in the 2.6.0-rc1 the new version has 1.7x faster performance in comparison to Ruby 2.5 on CPU-intensive non-trivial benchmark workload called Optcarrot. The goal is to achieve better performance on memory-intensive workload as well.

Endless Ranges

The new version of Ruby introduces an endless range (1..). This would change the mandatory second argument in range to an optional and will make infinite loops more readable.

An option to raise an exception in Kernel#system

In previous versions of Ruby when there was a failure in executing system commands, the return value was “false” and there was no exception in those cases. With the new version Ruby will provide an “:exception” option to let Kernel#system raise an error instead of returning false.

The #Then Method

After introducing the “yield_self” method back in Ruby 2.5 and making it possible to pass a block to any instance and put this instance inside a block as an argument, Ruby 2.6 is introducing the “then” method. It is an alias to “yield_self” and makes the code even more readable.

“else” without “rescue” causes a syntax error

While in Ruby 2.5 when using “else” without “rescue” in “begin…end” block it raised a warning, the 2.6 version will give an exception. This change is currently experimental.

Non-ASCII capital letter may be used in constant names

Until Ruby 2.6 class and module names couldn’t start with a non-ASCII capital character. If they did, a “class/module name must be CONSTANT” exception has been raised. These limitations will be removed and it will be allowed to define constants in languages other than English.

Binding#source_location

In previous versions of Ruby, if you want to know the file name with location and line number of the binding object, you would need to use “Binding#eval”. In Ruby 2.6 a more readable method will be added – “Binding#source_location”.

A number of speed improvements

-    Improved speed of “Proc#call”.
-    Reduced memory footprint of short-living memory objects by introducing Transient Heap support for Hash.

Ruby 2.6 seems like an awesome Christmas gift for every Ruby Developer. It is coming with some very cool updates and performance improvements and soon all be able to take advantage of them.