epitools 0.5.32 → 0.5.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/epitools/core_ext/numbers.rb +1 -1
- data/lib/epitools/core_ext/object.rb +20 -1
- data/lib/epitools/path.rb +1 -1
- data/spec/core_ext_spec.rb +23 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ef87f5b481da8299d67f99558bdd36e980a1f01
|
4
|
+
data.tar.gz: 8d0d98bb58b957051f1b8376ff748e4d08a7f88f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 08f077990e8518946eb3b0b0d30bc4f09b3daa867f386fa92ca183b38e5aa5c483ac1b8625ae9f7c2d6f95afe2e1a612fec68231d108f81fd0eb963f461a4989
|
7
|
+
data.tar.gz: bca8a6f90958e61e8f3f371effdee9d2e80ca6bb4b6511416bf552330861ff23cf7d13029f5514fe1646aa91f5269652311eac73bc3d78b2ea1b0521951d787c
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.33
|
@@ -58,7 +58,26 @@ class Object
|
|
58
58
|
copy
|
59
59
|
end
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
|
+
#
|
63
|
+
# Cache (memoize) the result of this method the first time it's called
|
64
|
+
# and return this value for all subsequent calls.
|
65
|
+
#
|
66
|
+
def self.memoize(*methods)
|
67
|
+
methods.each do |meth|
|
68
|
+
old_method = instance_method(meth)
|
69
|
+
|
70
|
+
if old_method.arity == 0
|
71
|
+
ivarname = "@#{meth}"
|
72
|
+
define_method meth do
|
73
|
+
instance_variable_get(ivarname) or instance_variable_set(ivarname, old_method.bind(self).call)
|
74
|
+
end
|
75
|
+
else
|
76
|
+
raise "Can't memoize methods with arguments. (YET.)"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
62
81
|
#
|
63
82
|
# Serialize this object to a binary String, using Marshal.dump.
|
64
83
|
#
|
data/lib/epitools/path.rb
CHANGED
data/spec/core_ext_spec.rb
CHANGED
@@ -96,6 +96,29 @@ describe Object do
|
|
96
96
|
a.map(&:self).should == a
|
97
97
|
end
|
98
98
|
|
99
|
+
it "memoizes" do
|
100
|
+
|
101
|
+
class Fake
|
102
|
+
|
103
|
+
def cacheme
|
104
|
+
@temp = !@temp
|
105
|
+
end
|
106
|
+
memoize :cacheme
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
f = Fake.new
|
111
|
+
f.instance_variable_get("@cacheme").should == nil
|
112
|
+
|
113
|
+
f.cacheme.should == true
|
114
|
+
f.instance_variable_get("@temp").should == true
|
115
|
+
f.instance_variable_get("@cacheme").should == true
|
116
|
+
|
117
|
+
f.cacheme.should == true
|
118
|
+
f.instance_variable_get("@temp").should == true
|
119
|
+
f.instance_variable_get("@cacheme").should == true
|
120
|
+
end
|
121
|
+
|
99
122
|
end
|
100
123
|
|
101
124
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: epitools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.33
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- epitron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|