Skip to content

Instantly share code, notes, and snippets.

@timruffles
Created December 4, 2012 12:07
Show Gist options
  • Save timruffles/4203147 to your computer and use it in GitHub Desktop.
Save timruffles/4203147 to your computer and use it in GitHub Desktop.
ruby pipeline lambdas
class Proc
def |(g)
lambda {|*args|
g.(self.(*args))
}
end
end
class Printer
def call(x)
puts "#{x}\n"
end
end
add_one = -> x { x+1 }
times_five = -> x { x*5 }
printer = Printer.new
(add_one | times_five | printer).(1)
(times_five | add_one | printer).(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment