top of page
Writer's pictureNishant Upadhyay

New features introduced in Ruby 2.7

In this article we are going to review the new features released with Ruby 2.7.0-preview1 last month.


There are three major features released last month.

  1. Compaction GC

  2. Pattern Matching

  3. REPL improvement


1. Compaction GC

This new feature has improved memory space allocation for your Ruby code. It defragment the fragmented memory space.


Sometimes your multithread application causes fragmentation which degrades your application performance but with GC.compact method one can defragment such space.

It compacts the heap by compacting the real objects from the heap.


2. Pattern Matching


Another major function introduced with Ruby 2.7 is "Pattern Matching". Here I am going to give you a very quick introduction about it and we will have a separate article for the detailed explanation on pattern matching.


Right now, pattern matching is widely used in functional programming languages.

Generally it traverse the provided object and assign its values if the pattern matches


Here is a very common example example:


3. REPL improvement

Now your IRB is supporting multi-line editing. Also result output of any command and core class are now colourised. It also provides rdoc integration. Checkout this video to understand this feature.



Some other notable changes in Ruby 2.7:

  1. A method reference operator, .:

  2. Numbered parameter as the default block parameter is introduced as an experimental feature.

  3. A beginless range is experimentally introduced. It might not be as useful as an endless range. ary[..3] # identical to ary[0..3]

  4. Enumerable#tally is added. It counts the occurrence of each element.

["a", "b", "c", "b"].tally

#=> {"a"=>1, "b"=>2, "c"=>1}


That's it. In my next article we will see how pattern matching works and how it is useful in our Ruby code. Keep reading!


Subscribe to my Newsletter to stay up to date with Ruby articles!


Have a happy coding!

566 views0 comments

Comments

Couldn’t Load Comments
It looks like there was a technical problem. Try reconnecting or refreshing the page.
bottom of page