memor 0.1.0 → 0.1.1
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/lib/memor.rb +2 -5
- data/lib/memor/version.rb +1 -1
- data/spec/lib/memor_spec.rb +43 -13
- metadata +8 -8
data/lib/memor.rb
CHANGED
@@ -2,6 +2,8 @@ require 'memor/version'
|
|
2
2
|
|
3
3
|
module Memor
|
4
4
|
|
5
|
+
private
|
6
|
+
|
5
7
|
# Example
|
6
8
|
#
|
7
9
|
# class Foo
|
@@ -39,7 +41,6 @@ module Memor
|
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
42
|
-
|
43
44
|
def _memor_args(memor_method, context_binding)
|
44
45
|
arg_names = _memor_arg_names(memor_method)
|
45
46
|
|
@@ -47,7 +48,6 @@ module Memor
|
|
47
48
|
context_binding.eval arg_name.to_s
|
48
49
|
end
|
49
50
|
end
|
50
|
-
private :_memor_args
|
51
51
|
|
52
52
|
def _memor_arg_names(memor_method)
|
53
53
|
# parameters is like [[:req, :a], [:req, :b], [:rest, :c], [:block, :d]]
|
@@ -57,7 +57,6 @@ module Memor
|
|
57
57
|
end
|
58
58
|
end.compact
|
59
59
|
end
|
60
|
-
private :_memor_arg_names
|
61
60
|
|
62
61
|
def _memor_with_no_arg(memor_name)
|
63
62
|
unless instance_variable_defined? memor_name
|
@@ -66,7 +65,6 @@ module Memor
|
|
66
65
|
|
67
66
|
instance_variable_get memor_name
|
68
67
|
end
|
69
|
-
private :_memor_with_no_arg
|
70
68
|
|
71
69
|
def _memor_with_args(memor_name, args)
|
72
70
|
unless instance_variable_defined? memor_name
|
@@ -82,6 +80,5 @@ module Memor
|
|
82
80
|
|
83
81
|
memor[key]
|
84
82
|
end
|
85
|
-
private :_memor_with_args
|
86
83
|
|
87
84
|
end
|
data/lib/memor/version.rb
CHANGED
data/spec/lib/memor_spec.rb
CHANGED
@@ -2,6 +2,23 @@ require 'spec_helper'
|
|
2
2
|
require 'memor'
|
3
3
|
|
4
4
|
describe Memor do
|
5
|
+
class Bar
|
6
|
+
extend Memor
|
7
|
+
@slows = 0
|
8
|
+
|
9
|
+
def self.bar
|
10
|
+
memor binding do
|
11
|
+
@slows += 1
|
12
|
+
|
13
|
+
'bar'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.slows
|
18
|
+
@slows
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
5
22
|
class Foo
|
6
23
|
include Memor
|
7
24
|
|
@@ -20,18 +37,24 @@ describe Memor do
|
|
20
37
|
def with_args1(a, b)
|
21
38
|
memor binding do
|
22
39
|
slow_method
|
40
|
+
|
41
|
+
[a, b]
|
23
42
|
end
|
24
43
|
end
|
25
44
|
|
26
45
|
def with_args2(*args)
|
27
46
|
memor binding do
|
28
47
|
slow_method
|
48
|
+
|
49
|
+
args
|
29
50
|
end
|
30
51
|
end
|
31
52
|
|
32
53
|
def with_args3(a, *args)
|
33
54
|
memor binding do
|
34
55
|
slow_method
|
56
|
+
|
57
|
+
[a, args].flatten
|
35
58
|
end
|
36
59
|
end
|
37
60
|
|
@@ -63,29 +86,29 @@ describe Memor do
|
|
63
86
|
foo.slows.should == 1
|
64
87
|
end
|
65
88
|
|
66
|
-
it '
|
67
|
-
foo.with_args1(1, 2).should ==
|
68
|
-
foo.with_args1(1, 2).should ==
|
69
|
-
foo.with_args1(2, 2).should ==
|
70
|
-
foo.with_args1(2, 2).should ==
|
89
|
+
it 'normal arguments' do
|
90
|
+
foo.with_args1(1, 2).should == [1, 2]
|
91
|
+
foo.with_args1(1, 2).should == [1, 2]
|
92
|
+
foo.with_args1(2, 2).should == [2, 2]
|
93
|
+
foo.with_args1(2, 2).should == [2, 2]
|
71
94
|
|
72
95
|
foo.slows.should == 2
|
73
96
|
end
|
74
97
|
|
75
98
|
it 'splat arguments' do
|
76
|
-
foo.with_args2(
|
77
|
-
foo.with_args2(
|
78
|
-
foo.with_args2(
|
79
|
-
foo.with_args2(
|
99
|
+
foo.with_args2(1).should == [1]
|
100
|
+
foo.with_args2(1).should == [1]
|
101
|
+
foo.with_args2(2).should == [2]
|
102
|
+
foo.with_args2(2).should == [2]
|
80
103
|
|
81
104
|
foo.slows.should == 2
|
82
105
|
end
|
83
106
|
|
84
107
|
it 'normal arguments and splat arguments' do
|
85
|
-
foo.with_args3(
|
86
|
-
foo.with_args3(
|
87
|
-
foo.with_args3(
|
88
|
-
foo.with_args3(
|
108
|
+
foo.with_args3(1, 4).should == [1, 4]
|
109
|
+
foo.with_args3(1, 4).should == [1, 4]
|
110
|
+
foo.with_args3(1, 5).should == [1, 5]
|
111
|
+
foo.with_args3(1, 5).should == [1, 5]
|
89
112
|
|
90
113
|
foo.slows.should == 2
|
91
114
|
end
|
@@ -110,4 +133,11 @@ describe Memor do
|
|
110
133
|
foo.send(:_memor_arg_names, foo.method(:with_args2)).should == [:args]
|
111
134
|
foo.send(:_memor_arg_names, foo.method(:with_args3)).should == [:a, :args]
|
112
135
|
end
|
136
|
+
|
137
|
+
it 'class methods' do
|
138
|
+
Bar.bar
|
139
|
+
Bar.bar.should == 'bar'
|
140
|
+
|
141
|
+
Bar.slows.should == 1
|
142
|
+
end
|
113
143
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: memor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-03-21 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &9713970 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *9713970
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: guard-rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &9713750 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *9713750
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: ruby-debug19
|
38
|
-
requirement: &
|
38
|
+
requirement: &9713530 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *9713530
|
47
47
|
description: memoize function without alias method chain
|
48
48
|
email:
|
49
49
|
- Aaron2Ti@gmail.com
|