curryer 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/curryer.rb +12 -16
- data/lib/curryer/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 625b48150e412a619902ea30d6e81a75064e3677
|
4
|
+
data.tar.gz: 1040e0def73820f0b2370fd711291bfa296162e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e1d167dbed5e91f1681a0e704a4df687c53d59edfa9b659ea618f58b7e89c8a3fb406fdbddaf9748562b04f853629ed22da46bfb143f5027911640333196b11
|
7
|
+
data.tar.gz: 80a7130d24b8a42e0cd43e0c2ac205fbeae8bd6190ad9700d6165e75a05e90aa859b4128400cbb773ff375b1c298f8f3091806e7f150b540ebee29549ec4cea5
|
data/lib/curryer.rb
CHANGED
@@ -57,36 +57,32 @@ module Curryer
|
|
57
57
|
reset_cache!
|
58
58
|
end
|
59
59
|
|
60
|
-
def
|
60
|
+
def __getobj__
|
61
61
|
@target
|
62
62
|
end
|
63
63
|
|
64
|
-
def
|
64
|
+
def __setobj__(new_target)
|
65
65
|
reset_cache!
|
66
66
|
@target = new_target
|
67
67
|
end
|
68
68
|
|
69
69
|
# See STLIB's delegate.rb. This is mostly just an adaption of what the
|
70
70
|
# base Delegate#method_missing is doing.
|
71
|
-
def method_missing(m, *local_args, &
|
72
|
-
target = self.
|
71
|
+
def method_missing(m, *local_args, &blk)
|
72
|
+
target = self.__getobj__
|
73
73
|
|
74
74
|
# Get the method, and put a partially-evaluated version of it in the cache
|
75
75
|
# so that we don't have to re-curry future calls. Then call it with the
|
76
76
|
# local args.
|
77
77
|
if target.respond_to?(m)
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
"Curried result #{result.inspect} is not callable but arguments #{local_args} were still given. " +
|
87
|
-
"You're trying to call the method with more arguments than it takes."
|
88
|
-
end
|
89
|
-
end
|
78
|
+
# Only once, make a closure for the method that applies the saved args
|
79
|
+
# to the method.
|
80
|
+
#
|
81
|
+
# Originally used Proc#curry, but doesn't work with certain
|
82
|
+
# metaprogramming styles that don't allow you to grab the metaprogrammed
|
83
|
+
# method.
|
84
|
+
result = @cache[m] ||= ->(*las, &b) { target.send(m, *(@args + las), &b) }
|
85
|
+
result.call(*local_args, &blk)
|
90
86
|
else
|
91
87
|
super(m, *local_args, &b)
|
92
88
|
end
|
data/lib/curryer/version.rb
CHANGED