One minute
Make Ruby Code More Readable with Kernel#then Alias
From Ruby 2.6.0-preview2
changelog [1]:
Add a new alias then to Kernel#yield_self. [Feature #14594]
This allows to chain method calls on an object, like so:
posts =
URI.parse("https://api.somewebsite.com/posts.json")
.then { |it| Net::HTTP.get(it) }
.then { |it| JSON.parse(it) }
[1] https://www.ruby-lang.org/en/news/2018/05/31/ruby-2-6-0-preview2-released/
Read other posts
comments powered by Disqus