Catch Ruby errors before your users do. Monitor Ruby production errors in real-time and debug them in minutes, before users notice. Our open source Ruby SDK works with Rails, Sinatra, and more. Use this link and get one month free!

RubyFlow The Ruby and Rails community linklog


The Ruby and Rails community linklog

Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!

Elixir/Unix style pipe operations in Ruby

This proof of concept demonstrates a concise/elegant syntax for pipelining and method composition!

-9.pipe { abs | Math.sqrt | to_i } #=> 3

[9, 64].map(&Math.pipe.sqrt)           #=> [3.0, 8.0]
[9, 64].map(&Math.pipe.sqrt.to_i.to_s) #=> ["3", "8"]

"".pipe do
  yield_self { |n| "Ruby has #{n} stars" }
#=> Ruby has 15120 stars

There’s been some recent discussions in the Ruby tracker related to method referencing and composition. The pipe_operator gem was created to propose an alternative syntax for this kind of behavior:

Is this something that you’d like to see in Ruby core? Please share your opinions!

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in