Occasionally when writing Ruby I find myself wanting a pipe method, similar to tap but returning the result of calling the block with self as a parameter, like this:
class Object
def pipe(&block)
block.call(self)
end
end
some_operation.pipe { |x| some_other_operation(x) }
..but so far I haven’t managed to find out what it’s called, if it exists. Does it exist?
If it doesn’t, I know I could monkey-patch object to add it but, y’know, that’s bad. Unless there’s a brilliant, guaranteed to never clash (and descriptive and short) name I could use for it…
This abstraction doesn’t exist in the core. I usually call it
as, it’s short and declarative:Raganwald usually mentions that abstraction in his posts, he calls it into.
So, summing it up, some names:
pipe,as,into,peg,thru.