It’s beginning to feel like tradition –– for the second year
now,
the Ruby core team has shipped a minor point update on Christmas Day.
This year gifting the world Ruby 2.3.

After reading up on this release, it feels more more like a major
point update, just for the sheer amount of work that must have been involved.
Part of the release seems to be paving the way
for immutability in Ruby 3.0
and a large chunk of the release provided new syntax and language features.

Let’s take a look at a few of the new features.
I was most looking forward to both the Hash#dig and Array#dig methods.
The “safe navigation” operator was added, which apparently is a
favorite of Matz.
Additionally, the did_you_mean gem is
now built into the language, a breakthrough for typo-driven-development of which
I am so fond.

Install Ruby 2.3.0

Once that’s done downloading and compiling, I like
chruby for switching to the new version.

chruby 2.3

Hash#dig and Array#dig

Both of these methods are great if you’re dealing with unwieldy data sets that you
may or may not have control over. Think complex API responses, legacy system interfaces,
etc. They allow you to safely traverse into the data structure without raising
an error if a single node in the lookup doesn’t exist.

Safe Navigation Operator

This is something that I hope people will use sparingly since it seems like it
would be a smell otherwise. The “safe navigation” operator allows you to call
a method on a variable that might be nil. Other languages, such as C# and Swift,
have a similar feature.

In Ruby it looks like this: &.

# assume nilly is nil because User was not foundnilly=User.find_by(username: "nilly")# Before Ruby 2.3nilly.notify!# NoMethodError error because nilly is nil!nilly&&nilly.notify!# avoid NoMethodError using short-circuit conditional# After Ruby 2.3nilly&.notify!# will only call notify! if nilly is not nil# => nil # just returns nil when object is nil

I can see this coming in handy in some situations, but I would consider using a
null object pattern
if I frequently found myself calling methods on something that is possibly nil.

did_you_mean

The did_you_mean gem is a nice little
tool that provides helpful suggestions when you mispell or tpyo a word. It’s
also nice when you might have a good idea of a method name, but need a
little help.