Skip to content

Instantly share code, notes, and snippets.

@falsetru
Last active Dec 19, 2015
Embed
What would you like to do?
class CurriedProc < Proc
attr_accessor :arity
def parameters
(1..arity).map { |i| [:opt, "_#{i}".to_sym] }
end
end
class Proc
def bind(pos, value)
raise ArgumentError.new("wrong position of argument (#{pos} for #{arity})") unless (1..arity).include?(pos)
ret = CurriedProc.new { |*args| call *args.insert(pos-1, value) }
ret.arity = arity - 1
ret
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment