dirty-memoize 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Binary file
@@ -0,0 +1,3 @@
1
+ === 0.0.4 / 2011-01-26
2
+ * Better specs
3
+ * Build managed with Hoe
File without changes
@@ -0,0 +1,11 @@
1
+ History.txt
2
+ LICENSE.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ examples/only_reader.rb
7
+ examples/reader_and_writer.rb
8
+ lib/dirty-memoize.rb
9
+ spec/dirty_memoize_spec.rb
10
+ spec/spec.opts
11
+ spec/spec_helper.rb
@@ -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
- require 'rake/rdoctask'
45
- Rake::RDocTask.new do |rdoc|
46
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
12
+ Hoe.plugin :git
47
13
 
48
- rdoc.rdoc_dir = 'rdoc'
49
- rdoc.title = "dirty-memoize #{version}"
50
- rdoc.rdoc_files.include('README*')
51
- rdoc.rdoc_files.include('lib/**/*.rb')
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
+
@@ -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+"_whitout_dirty").intern, sym)
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+"_whitout_dirty", *args)
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) {|*args|
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
@@ -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(:each) do
36
+ before do
43
37
  @ec=ExpensiveClass.new
44
38
  end
45
- it "should initialize with dirty? to true" do
46
- @ec.dirty?.should==true
47
- end
48
- it "should initialize with number of computation to 0" do
49
- @ec.compute_count.should==0
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
- describe "reads 'dirty' attributes " do
52
- before(:each) do
49
+ context "when reads 'dirty' attributes " do
50
+ before do
53
51
  @ec.a
54
52
  end
55
- it "#compute is called" do
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
- end
61
- it 'dirty? set to false' do
62
- @ec.dirty?.should==false
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
- describe "calls dirty writers before dirty getter" do
70
- before(:each) do
62
+ context "calls dirty writers before dirty getter" do
63
+ before do
71
64
  @ec.x="cache"
72
65
  end
73
- it 'set dirty? to true' do
74
- @ec.dirty?.should==true
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 call compute" do
77
- @ec.compute_called?.should==false
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(:each) do
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
- it 'set dirty? to false' do
90
- @ec.dirty?.should==false
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 or internal variable" do
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(:each) do
92
+ before do
105
93
  @ec.x='cache'
106
94
  @ec.a
107
95
  @ec.set_a('not_cache')
108
96
  end
109
- it "so changing internal variables doesn't produce external changes" do
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 "so deleting it implies calculate all again" do
115
- @ec.dirty?.should==false
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
- @ec.compute_count.should==2
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
@@ -1,12 +1,15 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
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
- - 3
9
- version: 0.0.3
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: 2010-04-01 00:00:00 -03:00
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: jeweler
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: "0"
67
+ version: 2.8.0
42
68
  type: :development
43
69
  version_requirements: *id002
44
- description: "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 "
45
- email: clbustos@gmail.com
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
- - LICENSE
52
- - README.rdoc
87
+ - History.txt
88
+ - LICENSE.txt
89
+ - Manifest.txt
90
+ - README.txt
53
91
  files:
54
- - .document
55
- - .gitignore
56
- - LICENSE
57
- - README.rdoc
92
+ - History.txt
93
+ - LICENSE.txt
94
+ - Manifest.txt
95
+ - README.txt
58
96
  - Rakefile
59
- - VERSION
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
- - --charset=UTF-8
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.6
131
+ rubyforge_project: dirty-memoize
132
+ rubygems_version: 1.3.7
91
133
  signing_key:
92
134
  specification_version: 3
93
- summary: Memoize like object, with dirty setters
94
- test_files:
95
- - spec/spec_helper.rb
96
- - spec/dirty_memoize_spec.rb
135
+ summary: "Like Memoize, but designed for mutable and parametizable objects Use when: 1"
136
+ test_files: []
137
+
Binary file
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC
@@ -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