simple_memoizer 0.0.1 → 0.1.0
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/README.md +36 -1
- data/lib/simple_memoizer.rb +1 -1
- 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: a32f127eaf2d6a20e972da6cbcb89911eeb5eb4c
|
4
|
+
data.tar.gz: 4677b553f99863b747853e7f5144022183e0a3a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2242d441f2aba9aa89748e459862c3ec64a225381480aba8cb767ca24e7f58d59a1d017f6e1eed4541f7807453490a39063e079a2e6fe3552560180e37ce6bd
|
7
|
+
data.tar.gz: 58db4a1d2fbc07635baf29ef35e4950ec4eb7ca56c41d95dae253659d64f8076fc74a4beb4342d357d4c2843c314414086e6ff13da2d1322c1ca75bedf020e14
|
data/README.md
CHANGED
@@ -1,4 +1,39 @@
|
|
1
1
|
Simple Memoizer
|
2
2
|
=====================
|
3
3
|
|
4
|
-
Allows you to memoize simple methods and works only on ruby 2
|
4
|
+
Allows you to memoize simple methods and works only on ruby 2.0.
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
```ruby
|
8
|
+
class Counter
|
9
|
+
def increment
|
10
|
+
@sum = 1 + @sum.to_i
|
11
|
+
end
|
12
|
+
|
13
|
+
memoize :increment
|
14
|
+
end
|
15
|
+
```
|
16
|
+
Your method will only be called the first time, the result will be stored and returned on subsequent invocations.
|
17
|
+
```irb
|
18
|
+
counter = Counter.new
|
19
|
+
=> Counter
|
20
|
+
|
21
|
+
counter.increment
|
22
|
+
=> 1
|
23
|
+
|
24
|
+
counter.increment
|
25
|
+
=> 1
|
26
|
+
|
27
|
+
counter.increment = 5
|
28
|
+
=> 5
|
29
|
+
|
30
|
+
counter.increment
|
31
|
+
=> 5
|
32
|
+
```
|
33
|
+
As you can see, it also provides an assignment operator, so you can override the memoized value :smiley:.
|
34
|
+
|
35
|
+
## Background
|
36
|
+
SimpleMemoizer uses Module#prepend to add the memoized method before yours in the method lookup path of your class. Your method is called by using 'super', because the class is an ancestor to the prepended module.
|
37
|
+
|
38
|
+
### Corolary
|
39
|
+
If you override a memoized method in a derived class, you alter the method chain, so the derived method won't be memoized unless you invoke memoize in the derived class as well.
|
data/lib/simple_memoizer.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_memoizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Máximo Mussini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|