The beauty (and horror) of Ruby is that you can do almost anything with it. I think this is a really interesting and clever use of the "can do anything" aspect of Ruby, although I think I'd prefer not to run into it in a production app.<p>Still, it's really cool to see how far we can push/mold the language to accomplish different tasks and patterns.
I've had a look at threading/piping operators in a few languages (list below). I'd say that Racket has the best one I've used. I love that you can specify a '_' for the hole which the result from the previous operation will fill. Julia's threading macro is surprisingly brittle, only letting you chain single-argument functions unless you want to use anonymous functions with one bound variable and the rest free.<p>+ Haskell :: <a href="https://www.schoolofhaskell.com/user/Gabriel439/Pipes%20tutorial" rel="nofollow">https://www.schoolofhaskell.com/user/Gabriel439/Pipes%20tuto...</a><p>+ Racket :: <a href="https://docs.racket-lang.org/threading/index.html" rel="nofollow">https://docs.racket-lang.org/threading/index.html</a><p>+ Clojure :: <a href="https://clojure.org/guides/threading_macros" rel="nofollow">https://clojure.org/guides/threading_macros</a><p>+ Julia :: <a href="https://syl1.gitbook.io/julia-language-a-concise-tutorial/useful-packages/pipe" rel="nofollow">https://syl1.gitbook.io/julia-language-a-concise-tutorial/us...</a><p>+ R :: <a href="https://r4ds.had.co.nz/pipes.html" rel="nofollow">https://r4ds.had.co.nz/pipes.html</a>
Check out this proof of concept gem to perform pipe operations in Ruby using block expressions:<p><a href="https://github.com/lendinghome/pipe_operator#-pipe_operator" rel="nofollow">https://github.com/lendinghome/pipe_operator#-pipe_operator</a><p><pre><code> "https://api.github.com/repos/ruby/ruby".pipe do
URI.parse
Net::HTTP.get
JSON.parse.fetch("stargazers_count")
yield_self { |n| "Ruby has #{n} stars" }
Kernel.puts
end
#=> Ruby has 15120 stars</code></pre>
While not as thorough solution as mentioned here in comments, UFCS goes a long way in this direction. In Next Generation Shell, I've designed the methods so that the first parameter is something that is likely to come from "the pipeline". Hence mylist.filter(...).map(...) just work. Combined with multiple dispatch and the fact that methods don't belong to a particular type/class, it allows creating user-defined methods with same convention to work with any existing and new types/classes.<p>UFCS - <a href="https://en.m.wikipedia.org/wiki/Uniform_Function_Call_Syntax" rel="nofollow">https://en.m.wikipedia.org/wiki/Uniform_Function_Call_Syntax</a>
Do the steps of the pipeline implementation in Ruby run concurrently?<p>I once did an Elixir course and really liked the pipelines. I continued implementing pipelines with a Scheme macro, but not concurrently.