Skip to content

Instantly share code, notes, and snippets.

@falsetru
Last active December 19, 2015 18:29
Show Gist options
  • Save falsetru/5998751 to your computer and use it in GitHub Desktop.
Save falsetru/5998751 to your computer and use it in GitHub Desktop.
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