Skip to content

Instantly share code, notes, and snippets.

@maxim
Created May 9, 2016 23:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxim/2373954284b65ca763a03e6c51ecacea to your computer and use it in GitHub Desktop.
Save maxim/2373954284b65ca763a03e6c51ecacea to your computer and use it in GitHub Desktop.
class Object
def pipe(meth, obj = self, args = [])
obj.public_send(meth, self, *args)
end
end
class Doubler
def double(c); c.map{|v| v*2} end
end
class Joiner
def join(c); c.join(',') end
end
[1,2,3,4].pipe(:double, Doubler.new).pipe(:join, Joiner.new)
# => "2,4,6,8"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment