Skip to content

Instantly share code, notes, and snippets.

@krisleech
Created October 12, 2019 22:12
Show Gist options
  • Select an option

  • Save krisleech/71b2c23fc696ab38b89bcf9165d19729 to your computer and use it in GitHub Desktop.

Select an option

Save krisleech/71b2c23fc696ab38b89bcf9165d19729 to your computer and use it in GitHub Desktop.
Piping in Ruby
require 'pry'
class Pipe
def self.pipe(*args)
new(args)
end
def self.[](*args)
new(args)
end
def initialize(args)
@args = args
end
def to_proc
Proc.new do |input|
@args.reduce(input) do |memo, arg|
memo.send(arg)
end
end
end
end
⏩ = Pipe
res = %w(1 2 3 4).map(&⏩[:to_i, :succ])
puts res.inspect # => [2,3,4,5]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment