What's new in Ruby 2.6

19 Jan 2019

Ruby 2.6 was released on Christmas day,
and brought a few interesting new features.
Here’s a quick summary of what’s changed.
As with my summaries of previous versions
(2.5,
2.4,
2.3)
I’m only summarizing
features that I find most interesting.
For a complete list of changes,
take a look at the
changelog.

Endless ranges

A new syntax was introduced to represent an endless range.
This will be useful when matching ranges in case statements.

exception keyword argument for Kernel methods

An exception keyword argument
was added for some Kernel methods
like Integer, Float and system.
For the Numeric methods,
we can now pass exception: false
to avoid raising when parsing an invalid value,
and to instead return nil.

Kernel#system, on the other hand,
accepts exception: true
to raise
if the command exits with non-zero exit status
(instead of returning false)
or if command execution fails
(instead of returning nil).

Performance improvements

The biggest news on the performance front
is that a JIT implementation,
called
MJIT,
was merged into Ruby.
This can be enabled
using the --jit flag.

MJIT has led to speedups in micro-benchmarks,
but isn’t mature enough yet
to work for larger codebases like Rails apps.
It is even slower for Rails than the non-JIT version.

However, this is an important step
towards the Ruby 3x3 goal,
which is to make Ruby 3
at least 3x faster that Ruby 2.0.
Currently Ruby 2.6 with JIT is
nearly 2.5x faster than 2.0
on the Optcarrot benchmark,
which is used
to compare the performance
of Ruby releases
for the 3x3 goal.

Aside from this,
a second garbage collection heap,
called Transient Heap,
was introduced,
which reduces memory usage
and improves GC speed
of short lived objects.
Proc.call and block.call

Better introspection

Ruby’s introspection abilities have been improved,
which the introduction
of the RubyVM::AbstractSyntaxTree class,
which lets us parse Ruby code into AST.
Binding.source_location was also added,
which returns an array containing
the file name and the line number
where it was called.

Links

Hi, I’m Nithin Bekal.
I work at Shopify in Ottawa, Canada.
Previously, co-founder of
CrowdStudio.in and
WowMakers.
Ruby is my preferred programming language,
and the topic of most of my articles here,
but I'm also a big fan of Elixir.
Tweet to me at @nithinbekal.