Merge pull request #2849 from cremno/proc-curry-should-preserve-lambdas

Proc#curry should preserve lambdas
This commit is contained in:
Yukihiro "Matz" Matsumoto
2015-06-23 14:51:36 +09:00
2 changed files with 6 additions and 1 deletions
+3 -1
View File
@@ -13,9 +13,11 @@ class Proc
end
def curry(arity=self.arity)
type = :proc
abs = lambda {|a| a < 0 ? -a - 1 : a}
arity = abs[arity]
if lambda?
type = :lambda
self_arity = self.arity
if (self_arity >= 0 && arity != self_arity) ||
(self_arity < 0 && abs[self_arity] > arity)
@@ -25,7 +27,7 @@ class Proc
pproc = self
make_curry = proc do |given_args=[]|
proc do |*args|
send(type) do |*args|
new_args = given_args + args
if new_args.size >= arity
pproc[*new_args]
+3
View File
@@ -41,6 +41,9 @@ assert('Proc#curry') do
assert_raise(ArgumentError) { b.curry[1, 2][3, 4] }
assert_raise(ArgumentError) { b.curry(5) }
assert_raise(ArgumentError) { b.curry(1) }
assert_false(proc{}.curry.lambda?)
assert_true(lambda{}.curry.lambda?)
end
assert('Proc#parameters') do