Created
May 9, 2016 23:06
-
-
Save maxim/2373954284b65ca763a03e6c51ecacea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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