Skip to content

Instantly share code, notes, and snippets.

@avit
Created September 26, 2014 16:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avit/f5a2bfb76d6c987b1eff to your computer and use it in GitHub Desktop.
Save avit/f5a2bfb76d6c987b1eff to your computer and use it in GitHub Desktop.
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