Skip to content

Instantly share code, notes, and snippets.

@maxim maxim/pipe.rb
Created May 9, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.