googleads
Ruby 2.6.0 Released! Explore The New Features In Ruby 2.6.0
preloder
Ruby Ruby on Rails

Ruby 2.6.0 Released! Here’s The Overview Of All New Features In Ruby 2.6.0

Recent Ruby 2.6.0 released really got some cool features which attracted me to explore more on it. On search of witnessing some major features i found handful of new updates which are really useful & optimistic. So, am planning to share all my views on its major features in this article. These updates includes Infinite Ranges, Ruby 2.6 benchmark, Ruby 2.6 Infinite Hashes, Ruby 2.6 union, Ruby 2.6 filter, Ruby 2.6 Enumerable chain and so much more. Let’s have a quick tour into ruby 2.6.0

Installing The Ruby 2.6.0 version:

 

  1. Click the link, it will download the zip file for you then you can extract that file.
  2. If you are using rvm then use this command to install “rvm install ruby-2.6.0”

Alright! You must be done with the installations. Now, let’s look into the futures.

New Features In Ruby 2.6.0 version

 

1) Infinite Ranges

In Ruby 2.6.0 we can use infinite ranges or endless ranges. Before 2.6 we can achieve endless ranges with Float::INFINITY, In Ruby 2.6.0 we can get endless ranges directly as i shown below.

 

 

In Ruby 2.6.0

 

2) Merging Hash By Passing Multiple Hashes As Arguments  

In previous versions, if we want to merge multiple hashes with one then we need to use merge 2 times as shown in below example.

Sample of merging hash2 and hash3 with hash1,

 

In Ruby 2.6.0

We can pass two hashes as arguments as shown below,

 

3) Bytes Method In Random Class

Ruby 2.6.0 introduces bytes method in Random class to get some random bytes.

We can also achieve this in older versions with the help of SecureRandom class bytes method.

 

In Ruby 2.6.0

You can use Random.bytes method which is 8 times faster than the SecureRandom. 

4) % in Ranges

This version introduces % in Ranges, this is an alias of step and here is an example to use this in ruby 2.6.0

Same thing you can achieve it using step as follows,

 

5) Union And Difference Methods In Array

This version introduces 2 new Array methods called union and difference which requires more efforts to get it done in older versions.

Now can easily perform array operations with this,

 

6) to_h accepts block

If we want to do some operations on Hash then we have to use map and to_h in old version. Ruby 2.6 accepts block to the to_h method.

Old Version

 

In Ruby 2.6

 

Similarly, we can use this in Ranges and Array too

 

7) Filter Method In Array

Ruby 2.6.0 introduces filter method in Array that works same like select and also it’s an alias of select.

 

In ruby 2.6.0

 

 

8) Enumerable chain and + methods

This returns Enumerable chain object.

Old Version

 

In Ruby 2.6.0

 

9) Handling Exceptions

Normally in ruby, it’s not possible to convert the string into integer and even If we try to convert it will get an exception.

 

Ruby 2.6.0 introduces adding exception option as a argument,

 

  Similarly, we can also add the exception argument to Integer(), Float(), Rational(), Complex() too.

10) ArithmeticSequence ‘first’ and ‘last’ methods

In Ruby 2.6.0, we can get the first and last elements in an Arithmetic sequence.

 

In 2.6.0, we can also compare the 2 Arithmetic sequences, for example

 

That’s all guys! Let us know your favorite features in comment section.

Want to learn more? Trying to be a smart coder? Curious to learn more  tactics from the group of Rubyfull stack experts! Subscribe us below to post you our top engaging blogs & tips.

Like What You're Reading ?

The following two tabs change content below.

Venkata Krishna

An ideal full stack software developer having 2 years of experience in Web app development and expertise in Ruby on Rails, CMS services. Let it be a technology or charity he never fails to feed the needy. An honest individual who continuously involves himself in creating Social Awareness as part of his life goals.

Leave a Reply

Your email address will not be published. Required fields are marked *

[contact-form-7 id="120788" title="Web Page Form"]

Schedule Your Call