memoit 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/Rakefile +4 -0
- data/lib/memoit.rb +2 -1
- data/lib/memoit/version.rb +1 -1
- data/spec/memoit_spec.rb +24 -0
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 441068286347f797f32789bc41d38aa58f7f28f9
|
4
|
+
data.tar.gz: 97f957be3579a93f742469e13f1059d52c5fd19e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bec090942ddc7b26f8312bacde3c84a1859e174fc4fa3cad6427fc8ecfc1d6b1a39fc3046977d2ff76c45bba3c10c6b8749d4cd6d569a4bae05effdb4dce219e
|
7
|
+
data.tar.gz: c60894c04f3f29a528730be230693c5610510d34b58656be597dd888cc4b6527976a0009e680ffc6c0ede10ee7d71a0659212474d1162fa726f8c0f2cd6a0f59
|
data/README.md
CHANGED
data/Rakefile
CHANGED
data/lib/memoit.rb
CHANGED
@@ -11,7 +11,8 @@ module Memoit
|
|
11
11
|
# end
|
12
12
|
# end
|
13
13
|
def memoize(name)
|
14
|
-
|
14
|
+
ivar_method_name = name.to_s.sub("?", "__questionmark").sub("!", "__bang")
|
15
|
+
ivar_name = "@_memo_#{ivar_method_name}".to_sym
|
15
16
|
mod = Module.new do
|
16
17
|
define_method(name) do |*args, &block|
|
17
18
|
return super(*args, &block) if block
|
data/lib/memoit/version.rb
CHANGED
data/spec/memoit_spec.rb
CHANGED
@@ -19,6 +19,18 @@ describe Memoit do
|
|
19
19
|
foo
|
20
20
|
false
|
21
21
|
end
|
22
|
+
|
23
|
+
memoize def query?
|
24
|
+
rand
|
25
|
+
end
|
26
|
+
|
27
|
+
memoize def bang!
|
28
|
+
rand
|
29
|
+
end
|
30
|
+
|
31
|
+
memoize def ☃
|
32
|
+
rand
|
33
|
+
end
|
22
34
|
end
|
23
35
|
end
|
24
36
|
let(:instance) { klass.new }
|
@@ -46,6 +58,18 @@ describe Memoit do
|
|
46
58
|
expect(instance.falsy).to eq(instance.falsy)
|
47
59
|
end
|
48
60
|
|
61
|
+
it "handles question-mark methods" do
|
62
|
+
expect(instance.query?).to eq(instance.query?)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "handles bang methods" do
|
66
|
+
expect(instance.bang!).to eq(instance.bang!)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "handles non-ASCII-name methods" do
|
70
|
+
expect(instance.☃).to eq(instance.☃)
|
71
|
+
end
|
72
|
+
|
49
73
|
it "returns the name of the method" do
|
50
74
|
name = nil
|
51
75
|
Class.new do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: memoit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Nicklas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,4 +94,3 @@ specification_version: 4
|
|
94
94
|
summary: Memoize is back!
|
95
95
|
test_files:
|
96
96
|
- spec/memoit_spec.rb
|
97
|
-
has_rdoc:
|