Skip to content

Instantly share code, notes, and snippets.

@melborne
Created April 26, 2014 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melborne/11316775 to your computer and use it in GitHub Desktop.
Save melborne/11316775 to your computer and use it in GitHub Desktop.
Yet Another Proc Composer in Ruby
class ProcCompressor
def initialize(n)
@proc = proc.curry(n+1)
end
def <<(arg)
@proc = @proc[arg]
Proc===@proc ? self : @proc
end
def to_proc
@proc
end
private
def proc
->*args{ args.inject(args.pop) { |mem, pr| pr.call(mem) } }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment