Beautify Ruby code with "then". One of the first things I was falling

22-Oct-2020 1268

One of the first things I was falling in love with Elixir was the pipe operator, which helps to turn deeply nested functions into a clear chain of function calls. Does it look beautiful..I have used to want something similar in Ruby. And fortunately starting from 2.5 version yield_self and lately then were added. It passes a block to the instance, gets that instance inside, and returns the result of the block. In some cases, it could improve code readability significantly.While working in the Integrations team at CoverWallet we often handle a lot of API responses. A not long time ago I needed to parse the multipart body response, fetch a pdf document from there and make some manipulations with it. Before Ruby 2.5 code would look something like this:.

Use coupon code:

RUBYONRAILS

to get 30% discount on our bundle!
Prepare for your next tech interview with our comprehensive collection of programming interview guides. Covering JavaScript, Ruby on Rails, React, and Python, these highly-rated books offer thousands of essential questions and answers to boost your interview success. Buy our 'Ultimate Job Interview Preparation eBook Bundle' featuring 2200+ questions across multiple languages. Ultimate Job Interview Preparation eBook Bundle