memoizer 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b010462b283416d36bc6de92c071b5010676f917
4
- data.tar.gz: 77daaef50543351dff8ca7ceb1e41c5e520495f6
3
+ metadata.gz: 9f15c5729b1a9844e6c5f4e75ce3994170d7544c
4
+ data.tar.gz: 707e892931dc2ebbef87efc266ee66347bba37e7
5
5
  SHA512:
6
- metadata.gz: 3e3ee325a2fb4709776b15d990af5c6b9c0bbf56238764a96265830bdb76dc0eb3de62798a31e2ed0bb8bdc662bbf7a5a32a9517cac8222f9dea2662bf1e0844
7
- data.tar.gz: d33e9225fe71f6c4785f71e4fb06c01fdf19e54887a52900883c3467c72cf86f267674b2fea30f754e7f20b6687b75fdd5a7dbd1c88afe6ba68a9883bf68baec
6
+ metadata.gz: c34f13ce47f80cd588e7acc06f38207fb2502689be3986b99af60ea8a20dc4e3ca353e81562a3392b3b96667f685ed51fec04d08a0f3345bf28cf2de38a9bc4a
7
+ data.tar.gz: e6cdf1930961c701e41c7ef7bd8705941aaeb60e49a883f7892a8a7d9e70151ec6f0ca0fe555c862cae1210982f694144547d91d9c85896976c95d691ffa51b7
@@ -9,7 +9,7 @@ module Memoizer
9
9
  end
10
10
 
11
11
  def self.ivar_name(method_name)
12
- "_memoized_#{self.safe_name(method_name)}"
12
+ :"@_memoized_#{self.safe_name(method_name)}"
13
13
  end
14
14
 
15
15
  module ClassMethods
@@ -18,19 +18,21 @@ module Memoizer
18
18
  memoized_ivar_name = Memoizer.ivar_name(method_name)
19
19
  unmemoized_method = "_unmemoized_#{method_name}"
20
20
 
21
- attr_accessor memoized_ivar_name
22
21
  alias_method unmemoized_method, method_name
23
22
 
24
23
  no_args = self.instance_method(unmemoized_method).arity == 0
25
24
 
26
25
  define_method method_name do |*args|
27
- memoized_value = self.instance_variable_get("@#{memoized_ivar_name}")
26
+
27
+ if instance_variable_defined?(memoized_ivar_name)
28
+ memoized_value = self.instance_variable_get(memoized_ivar_name)
29
+ end
28
30
 
29
31
  # if the method takes no inputs, store the value in an array
30
32
  if no_args
31
33
  if !memoized_value.is_a?(Array)
32
34
  memoized_value = [self.send(unmemoized_method)]
33
- self.instance_variable_set("@#{memoized_ivar_name}", memoized_value)
35
+ self.instance_variable_set(memoized_ivar_name, memoized_value)
34
36
  end
35
37
  memoized_value.first
36
38
 
@@ -38,7 +40,7 @@ module Memoizer
38
40
  else
39
41
  if !memoized_value.is_a?(Hash)
40
42
  memoized_value = {args => self.send(unmemoized_method, *args)}
41
- self.instance_variable_set("@#{memoized_ivar_name}", memoized_value)
43
+ self.instance_variable_set(memoized_ivar_name, memoized_value)
42
44
  elsif !memoized_value.has_key?(args)
43
45
  memoized_value[args] = self.send(unmemoized_method, *args)
44
46
  end
@@ -57,7 +59,7 @@ module Memoizer
57
59
 
58
60
  module InstanceMethods
59
61
  def unmemoize(method_name)
60
- self.instance_variable_set("@#{Memoizer.ivar_name(method_name)}", nil)
62
+ self.instance_variable_set(Memoizer.ivar_name(method_name), nil)
61
63
  end
62
64
 
63
65
  def unmemoize_all
@@ -1,3 +1,3 @@
1
1
  module Memoizer
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.3'
3
3
  end
@@ -2,3 +2,9 @@ require 'rubygems'
2
2
  require 'bundler/setup'
3
3
  require 'date'
4
4
  require 'timecop'
5
+
6
+ RSpec.configure do |config|
7
+ config.warnings = true
8
+ config.order = :random
9
+ Kernel.srand config.seed
10
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: memoizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Barun Singh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-12 00:00:00.000000000 Z
11
+ date: 2017-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  version: 1.3.6
92
92
  requirements: []
93
93
  rubyforge_project:
94
- rubygems_version: 2.5.1
94
+ rubygems_version: 2.6.11
95
95
  signing_key:
96
96
  specification_version: 4
97
97
  summary: Memoizes (caches the results of) your methods