Last month, Shane Emmons did a post on implementing pipe in ruby. Check out his post here.
As Shane mentioned, the unix pipe operator is extremely powerful and simple to use / understand. The result of the first operation is passed as the argument for the next operation and so on. Last summer, shortly before I came onboard, Shane implemented our first version:
1 2 3 4 5 6 def pipe(initial_env, through:) through.reduce(initial_env) do |env, method| status, _, _ = env success?(status
| (pipe) operator is an extremely powerful and simple tool. With it you can do amazing feats, like kill vagrant when it's misbehaving:
1 ps aux | grep vagrant | grep -v grep | tr -s " " | cut -d" " -f2 | xargs kill
or open every file that references
1 vi $(ag ShimMessageView -l --nocolor | xargs)
Simply stated, the
pipe takes input from the left, runs it through a command and outputs it on the right. Data in, data out. This pattern is so powerful, many languages,...