Skip to content

Instantly share code, notes, and snippets.

@avit
Created Sep 26, 2014
Embed
What would you like to do?
Simple ruby pipelines
class Object
def | other
case other
when Proc
if self.is_a?(Proc)
proc { |input| other.call( self.call(input) ) }
else
other.call(self)
end
else
super
end
end
end
"ruby" |-> r { r.upcase }
#=> "RUBY"
pipeline = &:upcase | &:reverse
"ruby" | pipeline
#=> "YRUB"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment