memo-it 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/README.md +23 -0
  4. data/lib/memo/it.rb +7 -3
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a8f78c7a50e8cbad98d26701c1e0f28a65787594
4
- data.tar.gz: f43cb631b0416a4188c51f11c301d3db6a0f7599
3
+ metadata.gz: 5ba70b290050e4ac1069de24e58bbe33b242fcf8
4
+ data.tar.gz: dd171e80509a3427abced4b6ab35f8d47fb168dc
5
5
  SHA512:
6
- metadata.gz: 05bdef9d4e2e040ac5906fe6b8cd879a337e92ebe591400abfa492a2a0b8663c44b8734edc179d3e7d850ea549488828c35d5025abf30649d19ed2b1e25b04bc
7
- data.tar.gz: 89d151fee8ec8a53ee5fb3fc8e6fc8509bc44ed6422e583b04cc1180203e19e2b48a652cbe69693a3fac0be6053d987b1345986623275287de01db5dee61f0a0
6
+ metadata.gz: 0a670f8c4f7a572c4ab62a58ff372796e44823d660466234c407f34a91582ed11c3b7bfd21006d07813843c5a9fe5efead90cee29b484ee85f9f0cb75f963434
7
+ data.tar.gz: 9a7bb9853224dc5414a29a5ba3bc688f7d6b23a0c160c4657d549b2282b88044c227419fca35acb71fe32c396687afecbdd896b925d9670105c116c5a3ca1c4c
data/.gitignore CHANGED
@@ -7,3 +7,7 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+
11
+ # personal version manager settings
12
+ .ruby-version
13
+ .ruby-gemset
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
@@ -1,9 +1,13 @@
1
1
  module Memo
2
- VERSION = '0.1.2'
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
- keys << block.binding.local_variables.map { |name| [name, block.binding.local_variable_get(name)] }
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.1.2
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-06 00:00:00.000000000 Z
11
+ date: 2017-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler