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

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:.


Beautify Ruby code with "then". One of the first things I was falling #ruby #rubydeveloper #rubyonrails #code https://rubyonrails.ba/single/beautify-ruby-code-with-then-one-of-the-first-things-i-was-falling

Nezir Zahirovic

Contractor Ruby On Rails (8+ years) / MCPD .Net / C# / Asp.Net / CSS / SQL / (11 years)

related articles