Earlier in April this year, the new versions for Ruby 2.6.3 and Rails 6.0.0 RC1 were announced on ruby-lang.org and rubyonrails.org respectively. We looked into the new versions to see how the features have improved, and how the revised features bring more clarity to developers’ work who utilize Ruby and Ruby on Rails.

What’s New in Rails 6.0.0 RC1
Rails 6.0.0 RC1 was released on April 24, 2019. It is the refined version of all the previously released beta versions. The main features of the version include parallel testing, Action Text, Action Mailbox, multiple database support, and Webpacker as default Javascript bundler.
The beta release, Rails 6.0.0.beta3 was released in the March of this year. The most highlighting features of Rails 6.0 are the two main frameworks: Action Text and Action Mailbox. In addition, there are scalable upgrades for parallel testing and multiple database support. Moreover, the new version includes around 1000 commits.

Below, we look at some of the main features of Rails 6.0 and their functionality.

Action Mailbox
The most prominent feature of the new version is the action mailbox that directs incoming emails to a controller-like mailbox. It transfers for Postmark, SendGrid, Mailgun, Amazon SES, Mandrill, and Mailgun with ingresses. Developers can also manage inbound emails through Qmail ingresses, built-in Exim, and Postfix.

Action Text
Action Text is a powerful feature that delivers rich text (content and editing) to Rails. It involves the Trix editor for managing the formatting, links, quotes, and embedded images, and everything in between. The content created by the Trix editor is stored in its individual RichText model that’s linked with any (existing) Active Record model. Embedded images and other attachments are saved using Active Storage and linked with the added RichText model.

Multiple Database Support
The multiple database support system makes it hassle-free for an individual application to link to various other databases concurrently. This feature is helpful in situations where you want to separate certain records into their own database for isolation purposes, or because you are reading/writing with an aim to split with similar databases for enhanced performance.

Parallel Testing Support
Parallel testing support feature allows for hassle-free test runs for group tests where each group has a separate database with its own thread. This feature is best suited for projects where there’s a need to run a number of tests.

Webpacker as Default Javascript Bundler
In this version, Webpacker is finally available through the new Javascript directory as the default Javascript bundler.

In addition to the above-mentioned features, Rails 6.0 is packed with minor fixes, changes, and upgrades that will readily allow you to do things faster. Some of the additional features include:

  • Proactive protection for DNS rebinding attacks
  • Proper action cable testing
  • Action cable JavaScript in ES6
  • Per-environment credentials

View more details in the framework’s CHANGELOG files.
Rails 6.0 and all the beta releases that led up to it were guided by Rafael França (the release manager) in collaboration with Kasper Timm Hansen.

What’s New in Ruby 2.6.3
Ruby 2.6.3 was released on April 17, 2019. The new version offers a number of features that allow for increased flexibility and scalability. You can view the details of the features at the official changelog. To install the latest version, visit the Ruby download page.

The main features are detailed below.

Endless ranges
In Ruby 2.6.3, there’s a new syntax that represents endless ranges. It is highly useful when you need to match different ranges in the case statements. In the previous version, the range was defined with an ending value; for example, (1...10). In the latest version, it is represented as: 1..Float::INFINITY.

Composing procs, methods, and lambdas
Composition feature in the new Ruby version readily allows for a distinct functional style. #<< and #>> functions are introduced in Method and Proc objects to allow their composition in the new method. With #>> function, the number is squared before _2 is added on the first Proc call. In the case of #<< function, the Proc call is reversed. With the new version, you get two different composing procs.

Kernel#then
This is not necessarily a new feature but a revised version of Kernel#yield_self, a function that was a part of Ruby 2.5. The feature allows for chained operation in the form of a pipeline.

require 'net/http'
require 'json'

url = 'https://api.github.com/repos/rails/rails'

def get_repo_description(url)
  uri = URI.parse(url)
  response = Net::HTTP.get(uri)
  data = JSON.parse(response)
  data['description']
end

def get_repo_description(url)
 url
  .yield_self { |url| URI.parse(url) }
  .yield_self { |uri| Net::HTTP.get(uri) }
  .yield_self { |response| JSON.parse(response) }
  .yield_self { |data| data['description'] }
end

Merge multiple hashes
In Ruby 2.5, the function Hash#merge was designed to take only a single argument. You could only merge multiple hashes through chain calls that are made to #merge. In the New version, you can now have multiple hashes.

Array#union and Array#difference
In the new version, the methods Array#union and Array#difference are similar to the & and | operators with an exception that they now accept more than one argument and are easy to chain.

Enumerable#to_h with block
In the newer version, the enumerable#to_h accepts a specific block that readily maps keys to the values. This is useful as it allows for hash transformation without creating any arrays using the map or without using reduce syntax.

Enumerator::arithmeticsequence
Ruby 2.6.3 has introduced a unique enumerable object called Enumerable::ArithmethicSequence. There are two distinct ways to get an ArithmethicSequence, namely Numeric#step and Range#step. This object knows the total number of elements in a sequence and the first and the last element in a sequence.

Performance improvements. In terms of performance, the new version comes with the JIT implementation, also known as MJIT. It can be enabled using --jit flag. It is important to note here that although MJIT has led to better speed in micro-benchmarks, it is still not mature enough to work with bigger codebases like the Rails app. In fact, it is slower for the Rails app as compared to the non-JIT version. But regardless, this is an important improvement for making sure that Ruby 3 is 3x faster than Ruby 2. Currently, the newer version is 2.5 x faster than Ruby 2.0.

In addition, Transient Heap is introduced in the newer version. It readily enhances GC speed and memory usage.

Enhanced introspection
Ruby’s introspection capabilities have significantly improved with the RubyVM::AbstractSyntaxTree class, which allows the code to parse into AST. In addition, Binding.source_location is also introduced, which delivers the array containing the line number and the file name.

Other changes include:

  • In this version, the flip flop syntax is deprecated and will very likely be removed in the coming versions.
  • Rubygems 3.0.1 is now a part of Ruby. Additionally, the bundler has been made the default gem, which means that there’s no need to install the bundler after the installation of Ruby.
  • In the new version, you will find Array#filter as an alias for #select.
  • The new version has introduced Random.bytes, which increase speed up to 8 times faster.

To view the comprehensive list of changes, see Victor Shepelev’s Ruby 2.6 changes list.

Are you looking to upgrade to the latest features of Ruby on Rails?
iRonin experts can help you incorporate the newest features into your process for enhanced product development. Get in touch with us to learn more about our services.