memoist 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/memoist.rb +22 -17
  2. metadata +3 -3
@@ -23,36 +23,41 @@ module Memoist
23
23
  end
24
24
 
25
25
  def memoize_all
26
- prime_cache ".*"
26
+ prime_cache
27
27
  end
28
28
 
29
29
  def unmemoize_all
30
- flush_cache ".*"
30
+ flush_cache
31
31
  end
32
32
 
33
33
  def prime_cache(*syms)
34
+ if syms.empty?
35
+ syms = methods.collect do |m|
36
+ m[12..-1] if m.to_s.start_with?("_unmemoized_")
37
+ end.compact
38
+ end
39
+
34
40
  syms.each do |sym|
35
- methods.each do |m|
36
- if m.to_s =~ /^_unmemoized_(#{sym})/
37
- if method(m).arity == 0
38
- __send__($1)
39
- else
40
- ivar = Memoist.memoized_ivar_for($1)
41
- instance_variable_set(ivar, {})
42
- end
43
- end
41
+ m = method(:"_unmemoized_#{sym}") rescue next
42
+ if m.arity == 0
43
+ __send__(sym)
44
+ else
45
+ ivar = Memoist.memoized_ivar_for(sym)
46
+ instance_variable_set(ivar, {})
44
47
  end
45
48
  end
46
49
  end
47
50
 
48
51
  def flush_cache(*syms)
52
+ if syms.empty?
53
+ syms = (methods + private_methods + protected_methods).collect do |m|
54
+ m[12..-1] if m.to_s.start_with?("_unmemoized_")
55
+ end.compact
56
+ end
57
+
49
58
  syms.each do |sym|
50
- (methods + private_methods + protected_methods).each do |m|
51
- if m.to_s =~ /^_unmemoized_(#{sym.to_s.gsub(/\?\Z/, '\?')})/
52
- ivar = Memoist.memoized_ivar_for($1)
53
- instance_variable_get(ivar).clear if instance_variable_defined?(ivar)
54
- end
55
- end
59
+ ivar = Memoist.memoized_ivar_for(sym)
60
+ instance_variable_get(ivar).clear if instance_variable_defined?(ivar)
56
61
  end
57
62
  end
58
63
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: memoist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -19,7 +19,7 @@ authors:
19
19
  autorequire:
20
20
  bindir: bin
21
21
  cert_chain: []
22
- date: 2012-01-24 00:00:00.000000000 Z
22
+ date: 2012-08-15 00:00:00.000000000 Z
23
23
  dependencies: []
24
24
  description:
25
25
  email:
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  version: '0'
67
67
  requirements: []
68
68
  rubyforge_project:
69
- rubygems_version: 1.8.10
69
+ rubygems_version: 1.8.24
70
70
  signing_key:
71
71
  specification_version: 3
72
72
  summary: memoize methods invocation