memo-it 0.1.2 → 0.2.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/.gitignore +4 -0
- data/README.md +23 -0
- data/lib/memo/it.rb +7 -3
- 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: 5ba70b290050e4ac1069de24e58bbe33b242fcf8
|
4
|
+
data.tar.gz: dd171e80509a3427abced4b6ab35f8d47fb168dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a670f8c4f7a572c4ab62a58ff372796e44823d660466234c407f34a91582ed11c3b7bfd21006d07813843c5a9fe5efead90cee29b484ee85f9f0cb75f963434
|
7
|
+
data.tar.gz: 9a7bb9853224dc5414a29a5ba3bc688f7d6b23a0c160c4657d549b2282b88044c227419fca35acb71fe32c396687afecbdd896b925d9670105c116c5a3ca1c4c
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -27,6 +27,29 @@ In case you want to memoize something that has parameters, memo-it will just use
|
|
27
27
|
end
|
28
28
|
```
|
29
29
|
|
30
|
+
If, on the other hand, you want to memoize parameters but ignore one of them,
|
31
|
+
you can do this by adding it to the `:ignore` list:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
def load_repo(name = 'memo-it', time = Time.now)
|
35
|
+
memo(ignore: :time) do
|
36
|
+
# in this case the result will be memoized per name
|
37
|
+
HTTPClient.get("https://github.com/phoet/#{name}?time=#{time}")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
Or provide a list of parameters to ignore:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
def load_repo(name = 'memo-it', time = Time.now, other = 'irrelevant')
|
46
|
+
memo(ignore: [:time, :other]) do
|
47
|
+
# in this case the result will be memoized per name
|
48
|
+
HTTPClient.get("https://github.com/phoet/#{name}?time=#{time}&other=#{other}")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
30
53
|
## Installation
|
31
54
|
|
32
55
|
### As a Gem
|
data/lib/memo/it.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
module Memo
|
2
|
-
VERSION = '0.
|
2
|
+
VERSION = '0.2.0'
|
3
3
|
module It
|
4
|
-
def memo(&block)
|
4
|
+
def memo(ignore: [], &block)
|
5
5
|
keys = block.source_location
|
6
|
-
|
6
|
+
ignore = Array(ignore)
|
7
|
+
keys << block.binding.local_variables.map do |name|
|
8
|
+
next if ignore.include?(name)
|
9
|
+
[name, block.binding.local_variable_get(name)]
|
10
|
+
end
|
7
11
|
keys = keys.flatten.map(&:to_s)
|
8
12
|
|
9
13
|
@_memo_it ||= {}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: memo-it
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- phoet
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|