dirty-memoize 0.0.3 → 0.0.4
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.
- data.tar.gz.sig +0 -0
- data/History.txt +3 -0
- data/{LICENSE → LICENSE.txt} +0 -0
- data/Manifest.txt +11 -0
- data/README.txt +64 -0
- data/Rakefile +14 -46
- data/examples/only_reader.rb +34 -0
- data/examples/reader_and_writer.rb +40 -0
- data/lib/dirty-memoize.rb +5 -4
- data/spec/dirty_memoize_spec.rb +47 -51
- data/spec/spec_helper.rb +10 -7
- metadata +64 -23
- metadata.gz.sig +0 -0
- data/.document +0 -5
- data/.gitignore +0 -21
- data/README.rdoc +0 -37
- data/VERSION +0 -1
data.tar.gz.sig
ADDED
Binary file
|
data/History.txt
ADDED
data/{LICENSE → LICENSE.txt}
RENAMED
File without changes
|
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
= dirty-memoize
|
2
|
+
|
3
|
+
* http://github.com/clbustos/dirty-memoize
|
4
|
+
|
5
|
+
== DESCRIPTION
|
6
|
+
|
7
|
+
Like Memoize, but designed for mutable and parametizable objects
|
8
|
+
|
9
|
+
Use when:
|
10
|
+
1. You have one expensive method (\compute) which set many internal
|
11
|
+
variables. So, is preferable lazy evaluation of these dependent variables.
|
12
|
+
2. The expensive operation depends on one or more parameters
|
13
|
+
3. Changes on one or more parameters affect all dependent variables
|
14
|
+
4. You may want to hide the call of 'compute' operation
|
15
|
+
5. The user could want test several different parameters values
|
16
|
+
|
17
|
+
== SYNOPSIS
|
18
|
+
|
19
|
+
By default, the method to compute should be called \#compute.
|
20
|
+
Set constant DIRTY_COMPUTE to the name of other method if you need it
|
21
|
+
|
22
|
+
Example:
|
23
|
+
|
24
|
+
require 'dirty-memoize'
|
25
|
+
|
26
|
+
class Factorial
|
27
|
+
include DirtyMemoize
|
28
|
+
attr_reader :result
|
29
|
+
attr_writer :n
|
30
|
+
dirty_memoize :result
|
31
|
+
dirty_writer :n
|
32
|
+
|
33
|
+
def initialize
|
34
|
+
@n=nil
|
35
|
+
@result=nil
|
36
|
+
end
|
37
|
+
def fact(n)
|
38
|
+
return 1 if n==1
|
39
|
+
n*(fact(n-1))
|
40
|
+
end
|
41
|
+
def compute
|
42
|
+
puts "Computing the factorial!"
|
43
|
+
@result=fact(@n)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
a=Factorial.new
|
48
|
+
a.n=10
|
49
|
+
puts "Our object is dirty: #{a.dirty?}"
|
50
|
+
puts "The result is: #{a.result}"
|
51
|
+
puts "Our object is no longer dirty: #{a.dirty?}"
|
52
|
+
puts "And the result is cached without calling the compute method: #{a.result}"
|
53
|
+
puts "Now, n is changed to 5"
|
54
|
+
a.n=5
|
55
|
+
# Object is now dirty. So, compute will be called when we get result
|
56
|
+
puts "The result is: #{a.result}"
|
57
|
+
|
58
|
+
== Sugestions
|
59
|
+
|
60
|
+
* Fork, modify and do wathever you need with it.
|
61
|
+
|
62
|
+
== Copyright
|
63
|
+
|
64
|
+
Copyright (c) 2010-2011 Claudio Bustos. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -1,52 +1,20 @@
|
|
1
|
+
$:.unshift(File.expand_path(File.dirname(__FILE__)+"/lib"))
|
2
|
+
$:.unshift(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
1
4
|
require 'rubygems'
|
2
5
|
require 'rake'
|
6
|
+
require 'hoe'
|
7
|
+
require 'dirty-memoize'
|
8
|
+
require 'rspec'
|
9
|
+
require 'rspec/core/rake_task'
|
3
10
|
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "dirty-memoize"
|
8
|
-
gem.summary = %Q{Memoize like object, with dirty setters}
|
9
|
-
gem.description = %Q{Works like Memoize [http://raa.ruby-lang.org/project/memoize/http://raa.ruby-lang.org/project/memoize/], but with a global cache. Thats allows to delete all cache when you use #clean() or call one of the methods specified on #dirty_writer }
|
10
|
-
gem.email = "clbustos@gmail.com"
|
11
|
-
gem.homepage = "http://github.com/clbustos/dirty-memoize"
|
12
|
-
gem.authors = ["Claudio Bustos"]
|
13
|
-
gem.add_development_dependency 'rspec'
|
14
|
-
gem.add_development_dependency 'jeweler'
|
15
|
-
end
|
16
|
-
Jeweler::GemcutterTasks.new
|
17
|
-
rescue LoadError
|
18
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
-
end
|
20
|
-
|
21
|
-
require 'spec/rake/spectask'
|
22
|
-
Spec::Rake::SpecTask.new(:spec) do |spec|
|
23
|
-
spec.libs << 'lib' << 'spec'
|
24
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
25
|
-
end
|
26
|
-
|
27
|
-
begin
|
28
|
-
require 'rcov/rcovtask'
|
29
|
-
Rcov::RcovTask.new do |test|
|
30
|
-
test.libs << 'test'
|
31
|
-
test.pattern = 'test/**/test_*.rb'
|
32
|
-
test.verbose = true
|
33
|
-
end
|
34
|
-
rescue LoadError
|
35
|
-
task :rcov do
|
36
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
task :spec => :check_dependencies
|
41
|
-
|
42
|
-
task :default => :spec
|
43
11
|
|
44
|
-
|
45
|
-
Rake::RDocTask.new do |rdoc|
|
46
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
12
|
+
Hoe.plugin :git
|
47
13
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
14
|
+
h=Hoe.spec 'dirty-memoize' do
|
15
|
+
self.testlib=:rspec
|
16
|
+
self.rspec_options << "-c" << "-b"
|
17
|
+
self.developer('Claudio Bustos', 'clbustos_at_gmail.com')
|
18
|
+
self.version=DirtyMemoize::VERSION
|
19
|
+
self.extra_dev_deps << ["rspec",">=2.0"]
|
52
20
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
$:.unshift(File.expand_path(File.dirname(__FILE__)+"/../lib"))
|
2
|
+
# This example shows the use of dirty_memoize without dirty_writer.
|
3
|
+
# When we call the method marked with dirty_memoize on a dirty object
|
4
|
+
# compute method is called.
|
5
|
+
|
6
|
+
require 'dirty-memoize'
|
7
|
+
|
8
|
+
class Factorial
|
9
|
+
include DirtyMemoize
|
10
|
+
attr_reader :result
|
11
|
+
dirty_memoize :result
|
12
|
+
def initialize(n)
|
13
|
+
@n=n
|
14
|
+
@result=nil
|
15
|
+
end
|
16
|
+
def fact(n)
|
17
|
+
return 1 if n==1
|
18
|
+
n*(fact(n-1))
|
19
|
+
end
|
20
|
+
def compute
|
21
|
+
puts "Computing the factorial!"
|
22
|
+
@result=fact(@n)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
a=Factorial.new(10)
|
27
|
+
puts "Our object is dirty: #{a.dirty?}"
|
28
|
+
puts "The result is: #{a.result}"
|
29
|
+
puts "Our object is no longer dirty: #{a.dirty?}"
|
30
|
+
puts "And the result is cached without calling the compute method: #{a.result}"
|
31
|
+
a.clean_cache
|
32
|
+
# Object is now dirty. So, compute will be called when we get result
|
33
|
+
puts "The result is: #{a.result}"
|
34
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
$:.unshift(File.expand_path(File.dirname(__FILE__)+"/../lib"))
|
2
|
+
# This example shows the use of dirty_memoize with dirty_writer.
|
3
|
+
# When we call the method marked with dirty_memoize on a dirty object,
|
4
|
+
# compute method is called.
|
5
|
+
# Setting a value on a dirty_writer set the object to dirty
|
6
|
+
|
7
|
+
require 'dirty-memoize'
|
8
|
+
|
9
|
+
class Factorial
|
10
|
+
include DirtyMemoize
|
11
|
+
attr_reader :result
|
12
|
+
attr_writer :n
|
13
|
+
dirty_memoize :result
|
14
|
+
dirty_writer :n
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@n=nil
|
18
|
+
@result=nil
|
19
|
+
end
|
20
|
+
def fact(n)
|
21
|
+
return 1 if n==1
|
22
|
+
n*(fact(n-1))
|
23
|
+
end
|
24
|
+
def compute
|
25
|
+
puts "Computing the factorial!"
|
26
|
+
@result=fact(@n)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
a=Factorial.new
|
31
|
+
a.n=10
|
32
|
+
puts "Our object is dirty: #{a.dirty?}"
|
33
|
+
puts "The result is: #{a.result}"
|
34
|
+
puts "Our object is no longer dirty: #{a.dirty?}"
|
35
|
+
puts "And the result is cached without calling the compute method: #{a.result}"
|
36
|
+
puts "Now, n is changed to 5"
|
37
|
+
a.n=5
|
38
|
+
# Object is now dirty. So, compute will be called when we get result
|
39
|
+
puts "The result is: #{a.result}"
|
40
|
+
|
data/lib/dirty-memoize.rb
CHANGED
@@ -29,6 +29,7 @@
|
|
29
29
|
# puts ExpensiveCalculation.new(1,2).a
|
30
30
|
|
31
31
|
module DirtyMemoize
|
32
|
+
VERSION="0.0.4"
|
32
33
|
# Trick from http://github.com/ecomba/memoizable
|
33
34
|
def self.included(receiver) #:nodoc:
|
34
35
|
receiver.extend DirtyMemoize::ClassMethods
|
@@ -38,10 +39,10 @@ module DirtyMemoize
|
|
38
39
|
def dirty_writer(*independent)
|
39
40
|
independent.each do |sym|
|
40
41
|
sym=sym.to_s+"="
|
41
|
-
alias_method((sym.to_s+"
|
42
|
+
alias_method((sym.to_s+"_without_dirty").intern, sym)
|
42
43
|
define_method(sym) do |*args|
|
43
44
|
@dirty=:true
|
44
|
-
send(sym.to_s+"
|
45
|
+
send(sym.to_s+"_without_dirty", *args)
|
45
46
|
end
|
46
47
|
end
|
47
48
|
end
|
@@ -49,7 +50,7 @@ module DirtyMemoize
|
|
49
50
|
def dirty_memoize(*dependent)
|
50
51
|
dependent.each do |sym|
|
51
52
|
alias_method((sym.to_s+"_without_dirty").intern, sym)
|
52
|
-
define_method(sym)
|
53
|
+
define_method(sym) do |*args|
|
53
54
|
if(dirty?)
|
54
55
|
clean_cache
|
55
56
|
if self.class.const_defined? "DIRTY_COMPUTE"
|
@@ -63,7 +64,7 @@ module DirtyMemoize
|
|
63
64
|
end
|
64
65
|
@cache[sym]||=Hash.new
|
65
66
|
@cache[sym][args]||=send(sym.to_s+"_without_dirty", *args)
|
66
|
-
|
67
|
+
end
|
67
68
|
end
|
68
69
|
end
|
69
70
|
end # end of ClassMethods
|
data/spec/dirty_memoize_spec.rb
CHANGED
@@ -2,25 +2,19 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
2
|
|
3
3
|
class ExpensiveClass
|
4
4
|
attr_writer :x, :y
|
5
|
-
attr_reader :count
|
6
5
|
include DirtyMemoize
|
7
6
|
def initialize
|
8
7
|
@a=nil
|
9
8
|
@b=nil
|
10
9
|
@x='x'
|
11
10
|
@y='y'
|
12
|
-
@compute_called=false
|
13
11
|
end
|
14
12
|
def set_a(aa)
|
15
13
|
@a=aa
|
16
14
|
end
|
17
|
-
def compute_called?
|
18
|
-
@compute_called
|
19
|
-
end
|
20
15
|
def compute
|
21
16
|
@a=@x
|
22
17
|
@b=@y
|
23
|
-
@compute_called=true
|
24
18
|
end
|
25
19
|
def a
|
26
20
|
"@a=#{@a}"
|
@@ -39,61 +33,55 @@ class ExpensiveClass2 < ExpensiveClass
|
|
39
33
|
end
|
40
34
|
end
|
41
35
|
describe DirtyMemoize, "extended object" do
|
42
|
-
before
|
36
|
+
before do
|
43
37
|
@ec=ExpensiveClass.new
|
44
38
|
end
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
39
|
+
subject { @ec }
|
40
|
+
context "when instanciated" do
|
41
|
+
it { should be_dirty}
|
42
|
+
it "should initialize with number of computation to 0" do
|
43
|
+
@ec.compute_count.should==0
|
44
|
+
end
|
45
|
+
it "read inmediatly the correct value" do
|
46
|
+
@ec.a.should=='@a=x'
|
47
|
+
end
|
50
48
|
end
|
51
|
-
|
52
|
-
before
|
49
|
+
context "when reads 'dirty' attributes " do
|
50
|
+
before do
|
53
51
|
@ec.a
|
54
52
|
end
|
55
|
-
|
56
|
-
@ec.compute_called?.should==true
|
57
|
-
end
|
58
|
-
it 'compute_count set to 1' do
|
53
|
+
it 'call compute' do
|
59
54
|
@ec.compute_count.should==1
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
end
|
64
|
-
it "compute_count doesn't change with multiple calls" do
|
55
|
+
end
|
56
|
+
it{ should_not be_dirty}
|
57
|
+
it "call compute once and only once" do
|
65
58
|
5.times {@ec.a}
|
66
59
|
@ec.compute_count.should==1
|
67
60
|
end
|
68
61
|
end
|
69
|
-
|
70
|
-
before
|
62
|
+
context "calls dirty writers before dirty getter" do
|
63
|
+
before do
|
71
64
|
@ec.x="cache"
|
72
65
|
end
|
73
|
-
|
74
|
-
|
66
|
+
it { should be_dirty}
|
67
|
+
it "doesn't compute anything" do
|
68
|
+
@ec.compute_count.should==0
|
75
69
|
end
|
76
|
-
it "doesn't
|
77
|
-
@ec.
|
78
|
-
end
|
79
|
-
it "doesn't change dirty getters" do
|
80
|
-
@ec.instance_variable_get("@a").nil?.should==true
|
70
|
+
it "doesn't change internal variables" do
|
71
|
+
@ec.instance_variable_get("@a").should be_nil
|
81
72
|
end
|
82
73
|
end
|
83
74
|
|
84
|
-
describe "calls dirty getter after call dirty writer" do
|
85
|
-
before
|
75
|
+
describe "when calls dirty getter after call dirty writer" do
|
76
|
+
before do
|
86
77
|
@ec.x="cache"
|
87
78
|
@ec.a
|
88
79
|
end
|
89
|
-
|
90
|
-
|
91
|
-
end
|
92
|
-
it "calls compute, only once" do
|
93
|
-
@ec.compute_called?.should==true
|
80
|
+
it { @ec.should_not be_dirty}
|
81
|
+
it "calls compute only once" do
|
94
82
|
@ec.compute_count.should==1
|
95
83
|
end
|
96
|
-
it "set value
|
84
|
+
it "set value of internal variable" do
|
97
85
|
@ec.instance_variable_get("@a").should=='cache'
|
98
86
|
end
|
99
87
|
it 'set getter method with a different value' do
|
@@ -101,24 +89,32 @@ describe DirtyMemoize, "extended object" do
|
|
101
89
|
end
|
102
90
|
end
|
103
91
|
describe "uses cache" do
|
104
|
-
before
|
92
|
+
before do
|
105
93
|
@ec.x='cache'
|
106
94
|
@ec.a
|
107
95
|
@ec.set_a('not_cache')
|
108
96
|
end
|
109
|
-
it "
|
110
|
-
@ec.instance_variable_get("@a").should=='not_cache'
|
97
|
+
it "changing internal doesn't start compute" do
|
111
98
|
@ec.compute_count.should==1
|
112
|
-
@ec.a.should=='@a=cache'
|
113
99
|
end
|
114
|
-
it
|
115
|
-
|
116
|
-
@ec.clean_cache
|
117
|
-
@ec.dirty?.should==true
|
118
|
-
@ec.compute_count.should==1
|
100
|
+
it {should_not be_dirty}
|
101
|
+
it "doesn't change cache value" do
|
119
102
|
@ec.a.should=='@a=cache'
|
120
|
-
|
121
|
-
|
103
|
+
end
|
104
|
+
describe "when cleaning cache" do
|
105
|
+
before do
|
106
|
+
@ec.clean_cache
|
107
|
+
end
|
108
|
+
it {@ec.should be_dirty}
|
109
|
+
it "doesn't call compute" do
|
110
|
+
@ec.compute_count.should==1
|
111
|
+
end
|
112
|
+
describe "when get dirty attribute" do
|
113
|
+
it "returns correct value and call compute again" do
|
114
|
+
@ec.a.should=='@a=cache'
|
115
|
+
@ec.compute_count.should==2
|
116
|
+
end
|
117
|
+
end
|
122
118
|
end
|
123
119
|
end
|
124
120
|
describe "could call other computation method" do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
$:.unshift(File.expand_path(File.dirname(__FILE__)+"/../lib"))
|
2
|
+
begin
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start do
|
5
|
+
add_filter "/spec/"
|
6
|
+
add_group "Libraries", "lib"
|
7
|
+
end
|
8
|
+
rescue LoadError
|
9
|
+
end
|
10
|
+
require 'rspec'
|
3
11
|
require 'dirty-memoize.rb'
|
4
|
-
require 'spec'
|
5
|
-
require 'spec/autorun'
|
6
12
|
|
7
|
-
Spec::Runner.configure do |config|
|
8
|
-
|
9
|
-
end
|
10
13
|
|
11
14
|
class String
|
12
15
|
def deindent
|
metadata
CHANGED
@@ -5,58 +5,97 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 4
|
9
|
+
version: 0.0.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Claudio Bustos
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
|
-
cert_chain:
|
15
|
+
cert_chain:
|
16
|
+
- |
|
17
|
+
-----BEGIN CERTIFICATE-----
|
18
|
+
MIIDMjCCAhqgAwIBAgIBADANBgkqhkiG9w0BAQUFADA/MREwDwYDVQQDDAhjbGJ1
|
19
|
+
c3RvczEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
|
20
|
+
MB4XDTEwMDMyOTIxMzg1NVoXDTExMDMyOTIxMzg1NVowPzERMA8GA1UEAwwIY2xi
|
21
|
+
dXN0b3MxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
|
22
|
+
bTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALf8JVMGqE7m5kYb+PNN
|
23
|
+
neZv2pcXV5fQCi6xkyG8bi2/SIFy/LyxuvLzEeOxBeaz1Be93bayIUquOIqw3dyw
|
24
|
+
/KXWa31FxuNuvAm6CN8fyeRYX/ou4cw3OIUUnIvB7RMNIu4wbgeM6htV/QEsNLrv
|
25
|
+
at1/mh9JpqawPrcjIOVMj4BIp67vmzJCaUf+S/H2uYtSO09F+YQE3tv85TPeRmqU
|
26
|
+
yjyXyTc/oJiw1cXskUL8UtMWZmrwNLHXuZWWIMzkjiz3UNdhJr/t5ROk8S2WPznl
|
27
|
+
0bMy/PMIlAbqWolRn1zl2VFJ3TaXScbqImY8Wf4g62b/1ZSUlGrtnLNsCYXrWiso
|
28
|
+
UPUCAwEAAaM5MDcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFGu9
|
29
|
+
rrJ1H64qRmNNu3Jj/Qjvh0u5MA0GCSqGSIb3DQEBBQUAA4IBAQCV0Unka5isrhZk
|
30
|
+
GjqSDqY/6hF+G2pbFcbWUpjmC8NWtAxeC+7NGV3ljd0e1SLfoyBj4gnFtFmY8qX4
|
31
|
+
K02tgSZM0eDV8TpgFpWXzK6LzHvoanuahHLZEtk/+Z885lFene+nHadkem1n9iAB
|
32
|
+
cs96JO9/JfFyuXM27wFAwmfHCmJfPF09R4VvGHRAvb8MGzSVgk2i06OJTqkBTwvv
|
33
|
+
JHJdoyw3+8bw9RJ+jLaNoQ+xu+1pQdS2bb3m7xjZpufml/m8zFCtjYM/7qgkKR8z
|
34
|
+
/ZZt8lCiKfFArppRrZayE2FVsps4X6WwBdrKTMZ0CKSXTRctbEj1BAZ67eoTvBBt
|
35
|
+
rpP0jjs0
|
36
|
+
-----END CERTIFICATE-----
|
16
37
|
|
17
|
-
date:
|
38
|
+
date: 2011-01-26 00:00:00 -03:00
|
18
39
|
default_executable:
|
19
40
|
dependencies:
|
20
41
|
- !ruby/object:Gem::Dependency
|
21
42
|
name: rspec
|
22
43
|
prerelease: false
|
23
44
|
requirement: &id001 !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
24
46
|
requirements:
|
25
47
|
- - ">="
|
26
48
|
- !ruby/object:Gem::Version
|
27
49
|
segments:
|
50
|
+
- 2
|
28
51
|
- 0
|
29
|
-
version: "0"
|
52
|
+
version: "2.0"
|
30
53
|
type: :development
|
31
54
|
version_requirements: *id001
|
32
55
|
- !ruby/object:Gem::Dependency
|
33
|
-
name:
|
56
|
+
name: hoe
|
34
57
|
prerelease: false
|
35
58
|
requirement: &id002 !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
36
60
|
requirements:
|
37
61
|
- - ">="
|
38
62
|
- !ruby/object:Gem::Version
|
39
63
|
segments:
|
64
|
+
- 2
|
65
|
+
- 8
|
40
66
|
- 0
|
41
|
-
version:
|
67
|
+
version: 2.8.0
|
42
68
|
type: :development
|
43
69
|
version_requirements: *id002
|
44
|
-
description:
|
45
|
-
|
70
|
+
description: |-
|
71
|
+
Like Memoize, but designed for mutable and parametizable objects
|
72
|
+
|
73
|
+
Use when:
|
74
|
+
1. You have one expensive method (\compute) which set many internal
|
75
|
+
variables. So, is preferable lazy evaluation of these dependent variables.
|
76
|
+
2. The expensive operation depends on one or more parameters
|
77
|
+
3. Changes on one or more parameters affect all dependent variables
|
78
|
+
4. You may want to hide the call of 'compute' operation
|
79
|
+
5. The user could want test several different parameters values
|
80
|
+
email:
|
81
|
+
- clbustos_at_gmail.com
|
46
82
|
executables: []
|
47
83
|
|
48
84
|
extensions: []
|
49
85
|
|
50
86
|
extra_rdoc_files:
|
51
|
-
-
|
52
|
-
-
|
87
|
+
- History.txt
|
88
|
+
- LICENSE.txt
|
89
|
+
- Manifest.txt
|
90
|
+
- README.txt
|
53
91
|
files:
|
54
|
-
- .
|
55
|
-
- .
|
56
|
-
-
|
57
|
-
- README.
|
92
|
+
- History.txt
|
93
|
+
- LICENSE.txt
|
94
|
+
- Manifest.txt
|
95
|
+
- README.txt
|
58
96
|
- Rakefile
|
59
|
-
-
|
97
|
+
- examples/only_reader.rb
|
98
|
+
- examples/reader_and_writer.rb
|
60
99
|
- lib/dirty-memoize.rb
|
61
100
|
- spec/dirty_memoize_spec.rb
|
62
101
|
- spec/spec.opts
|
@@ -67,10 +106,12 @@ licenses: []
|
|
67
106
|
|
68
107
|
post_install_message:
|
69
108
|
rdoc_options:
|
70
|
-
- --
|
109
|
+
- --main
|
110
|
+
- README.txt
|
71
111
|
require_paths:
|
72
112
|
- lib
|
73
113
|
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
74
115
|
requirements:
|
75
116
|
- - ">="
|
76
117
|
- !ruby/object:Gem::Version
|
@@ -78,6 +119,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
78
119
|
- 0
|
79
120
|
version: "0"
|
80
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
81
123
|
requirements:
|
82
124
|
- - ">="
|
83
125
|
- !ruby/object:Gem::Version
|
@@ -86,11 +128,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
128
|
version: "0"
|
87
129
|
requirements: []
|
88
130
|
|
89
|
-
rubyforge_project:
|
90
|
-
rubygems_version: 1.3.
|
131
|
+
rubyforge_project: dirty-memoize
|
132
|
+
rubygems_version: 1.3.7
|
91
133
|
signing_key:
|
92
134
|
specification_version: 3
|
93
|
-
summary: Memoize
|
94
|
-
test_files:
|
95
|
-
|
96
|
-
- spec/dirty_memoize_spec.rb
|
135
|
+
summary: "Like Memoize, but designed for mutable and parametizable objects Use when: 1"
|
136
|
+
test_files: []
|
137
|
+
|
metadata.gz.sig
ADDED
Binary file
|
data/.document
DELETED
data/.gitignore
DELETED
data/README.rdoc
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
= dirty-memoize
|
2
|
-
|
3
|
-
Like Memoize, but designed for mutable and parametizable objects
|
4
|
-
|
5
|
-
Use when:
|
6
|
-
1. You have one expensive method (\compute) which set many internal
|
7
|
-
variables. So, is preferable lazy evaluation of these dependent variables.
|
8
|
-
2. The expensive operation depends on one or more parameters
|
9
|
-
3. Changes on one or more parameters affect all dependent variables
|
10
|
-
4. You may want to hide the call of 'compute' operation
|
11
|
-
5. The user could want test several different parameters values
|
12
|
-
|
13
|
-
By default, the method to compute should be called \#compute.
|
14
|
-
Set constant DIRTY_COMPUTE to the name of other method if you need it
|
15
|
-
|
16
|
-
Example:
|
17
|
-
|
18
|
-
class ExpensiveCalculation
|
19
|
-
include DirtyMemoize
|
20
|
-
attr_reader :a
|
21
|
-
attr_accesor :x
|
22
|
-
# Your evil function
|
23
|
-
def compute
|
24
|
-
@a=x**x**x
|
25
|
-
end
|
26
|
-
end
|
27
|
-
a=new ExpensiveCalculation
|
28
|
-
a.x=1
|
29
|
-
puts a.a
|
30
|
-
|
31
|
-
== Sugestions
|
32
|
-
|
33
|
-
* Fork, modify and do wathever you need with it.
|
34
|
-
|
35
|
-
== Copyright
|
36
|
-
|
37
|
-
Copyright (c) 2010 Claudio Bustos. See LICENSE for details.
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.0.3
|