Top 10 Latvia-Based Software Development Companies
Learn about Latvia's top software development companies and their innovative solutions in our latest article. Discover how these tech leaders can help elevate your business.
Released quite recently, Ruby 2.6 brings a bunch of conveniences that may be worth taking a glimpse of. What is new? Let’s give it a shot!
Ruby 2.6 introduces endless ranges, which makes expressions like:
possible.
Ruby 2.6 provides new methods and aliases for Array class. I.e:
Hash#merge and Hash#merge! accept now multiple arguments. No more code like: hash1.merge(hash2).merge(hash3)!
Ruby 2.6 provides method Kernel#then, which is an alias to Kernel#yield_self, allowing us to chain operations into pipelines and making the code more readable.
Ruby 2.6 provides Enumerable#to_h method which accepts a block and maps keys to values!
Let’s remind shortly how we had to deal with creating a hash out of array before Ruby 2.6:
From now on, it’s possible to do this simply like this:
How cool is that!
Since Ruby 2.6 Proc#>> and Proc#<< methods were added, allowing us to combine two functions. Let’s look at this:
With the #>> operation, the number gets into exponentiation function first and then minus_two is performed on the result of the first function call. Although it seems useful and gives us a bit of magic, that we all love Ruby for, some say that code written like this becomes just an unreadable mess.
These are, in my opinion, the most interesting conveniences which Ruby 2.6 provides us with. I highly recommend taking a glimpse of official changelog too.
Read also:
– Writing documentation has become easy thanks to VuePress