tbpgr_utils 0.0.20 → 0.0.21
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/README.md +13 -0
- data/lib/open_classes/array.rb +232 -218
- data/lib/tbpgr_utils/version.rb +1 -1
- data/spec/open_classes/array_spec.rb +46 -0
- metadata +12 -12
data/README.md
CHANGED
@@ -22,6 +22,7 @@ Or install it yourself as:
|
|
22
22
|
|:----------- |:------------ |
|
23
23
|
|[TbpgrUtils Array#together](#arraytogether) |loop all arrays by block |
|
24
24
|
|[TbpgrUtils Array#together_at](#arraytogether_at) |together version of Array#at. together_at has alias :tat |
|
25
|
+
|[TbpgrUtils Array#together_clear](#arraytogether_clear) |together version of Array#clear. together_clear has alias :tclear |
|
25
26
|
|[TbpgrUtils Array#together_concat](#arraytogether_concat) |together version of Array#concat. together_concat has alias :tconcat |
|
26
27
|
|[TbpgrUtils Array#together_map](#arraytogether_mapor-tmap-together_collect-tcollect) |together version of Enumerable#map. together_map has aliases [:tmap, :together_collect, :tcollect] |
|
27
28
|
|[TbpgrUtils Array#together_reduce](#arraytogether_reduceor-treduce-together_inject-tinject) |together version of Enumerable#reduce. together_reduce has aliases [:treduce, :together_inject, :tinject] |
|
@@ -77,6 +78,17 @@ print [alpha, numbers].together_at 2 # => output ['three', nil]
|
|
77
78
|
|
78
79
|
[back to list](#list)
|
79
80
|
|
81
|
+
### Array#together_clear
|
82
|
+
~~~ruby
|
83
|
+
require 'tbpgr_utils'
|
84
|
+
|
85
|
+
alpha = %w{one two three}
|
86
|
+
numbers = %w{1 2 3}
|
87
|
+
[alpha, numbers].together_clear # => [[], []]
|
88
|
+
~~~
|
89
|
+
|
90
|
+
[back to list](#list)
|
91
|
+
|
80
92
|
### Array#together_concat
|
81
93
|
~~~ruby
|
82
94
|
require 'tbpgr_utils'
|
@@ -784,6 +796,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
|
|
784
796
|
https://github.com/tbpgr/tbpgr_utils_snippets
|
785
797
|
|
786
798
|
## History
|
799
|
+
* version 0.0.21 : add Array#together_clear. together_clear has alias :tclear
|
787
800
|
* version 0.0.20 : add Array#together_at. together_at has alias :tat
|
788
801
|
* version 0.0.19 : add AttributesHashable module.
|
789
802
|
* version 0.0.18 : add Array#together_concat. together_concat has alias :tconcat
|
data/lib/open_classes/array.rb
CHANGED
@@ -1,218 +1,232 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'open_classes/object'
|
3
|
-
require 'open_classes/module'
|
4
|
-
|
5
|
-
# Array
|
6
|
-
class Array
|
7
|
-
# Arrays loop together.
|
8
|
-
#
|
9
|
-
# alpha = %w{one two three}
|
10
|
-
# numbers = %w{1 2 3}
|
11
|
-
# [alpha, numbers].together do |first, second|
|
12
|
-
# print "#{first}:#{second}\n" # => output one:1, two:2, three:3
|
13
|
-
# end
|
14
|
-
def together
|
15
|
-
if_not_contain_array_rails_type_error
|
16
|
-
first.each_with_index do |i_v, i|
|
17
|
-
eval_each_str = get_args_str_for_together i
|
18
|
-
instance_eval "yield(#{eval_each_str})"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
# Arrays loop together with index.
|
23
|
-
#
|
24
|
-
# alpha = %w{one two three}
|
25
|
-
# numbers = %w{1 2 3}
|
26
|
-
# [alpha, numbers].together_with_index do |first, second, index|
|
27
|
-
# print "#{index.to_s}:#{first}:#{second}\n" # => output 0:one:1, 1:two:2, 2:three:3
|
28
|
-
# end
|
29
|
-
def together_with_index
|
30
|
-
if_not_contain_array_rails_type_error
|
31
|
-
first.each_with_index do |i_v, i|
|
32
|
-
eval_each_str = get_args_str_for_together i, true
|
33
|
-
instance_eval "yield(#{eval_each_str})"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
# Arrays together map.
|
38
|
-
#
|
39
|
-
# together_map has aliases [:tmap, :together_collect, :tcollect]
|
40
|
-
#
|
41
|
-
# if you want to single Array return
|
42
|
-
# alpha = %w{one two three}
|
43
|
-
# numbers = %w{1 2 3}
|
44
|
-
# print [alpha, numbers].together_map do |first, second|
|
45
|
-
# "#{first}:#{second}\n"
|
46
|
-
# end # => output one:1, two:2, three:3
|
47
|
-
#
|
48
|
-
# if you want to multi Array return
|
49
|
-
# alpha = %w{one two three}
|
50
|
-
# numbers = %w{1 2 3}
|
51
|
-
# print [alpha, numbers].together_map do |first, second|
|
52
|
-
# ["#{first}:#{second}", "#{second}:#{first}"]
|
53
|
-
# end # => output [['1:one', '2:two', '3:three'], ['one:1', 'two:2', 'three:3']]
|
54
|
-
def together_map
|
55
|
-
if_not_contain_array_rails_type_error
|
56
|
-
ret = []
|
57
|
-
first.each_with_index do |i_v, i|
|
58
|
-
eval_each_str = get_args_str_for_together i
|
59
|
-
each_ret = instance_eval "yield(#{eval_each_str})"
|
60
|
-
ret = set_together_each_return_map(ret, each_ret, i)
|
61
|
-
end
|
62
|
-
ret
|
63
|
-
end
|
64
|
-
|
65
|
-
# Arrays loop together select.
|
66
|
-
#
|
67
|
-
# together_select has aliases [:tselect, :together_find_all, :tfindall]
|
68
|
-
#
|
69
|
-
# if you want to single Array return
|
70
|
-
# firsts = [1, 2, 3, 4]
|
71
|
-
# seconds = [4, 2, 3, 1]
|
72
|
-
# ret = [firsts, seconds].together_select{|first, second|first == second}
|
73
|
-
# print ret # => output [[2, 3], [2, 3]]
|
74
|
-
#
|
75
|
-
# if you want to multi Array return
|
76
|
-
# firsts = [1, 2, 3, 4]
|
77
|
-
# seconds = [4, 2, 3, 1]
|
78
|
-
# ret = [firsts, seconds].together_select{|first, second|[first.odd?, second.even?]}
|
79
|
-
# print ret # => output [[1, 3], [4, 2]]
|
80
|
-
def together_select
|
81
|
-
if_not_contain_array_rails_type_error
|
82
|
-
ret = []
|
83
|
-
first.each_with_index do |i_v, i|
|
84
|
-
eval_each_str = get_args_str_for_together i
|
85
|
-
each_ret = instance_eval "yield(#{eval_each_str})"
|
86
|
-
ret = set_together_each_return_select(ret, each_ret, i)
|
87
|
-
end
|
88
|
-
ret
|
89
|
-
end
|
90
|
-
|
91
|
-
# Arrays loop together reduce.
|
92
|
-
#
|
93
|
-
# together_reduce has aliases [:treduce, :together_inject, :tinject]
|
94
|
-
#
|
95
|
-
# if you want to single return
|
96
|
-
# firsts = [1, 2, 3, 4]
|
97
|
-
# seconds = [4, 2, 3, 1]
|
98
|
-
# ret = [firsts, seconds].together_reduce{|memo, first, second|memo + first + second}
|
99
|
-
# print ret # => output 20
|
100
|
-
#
|
101
|
-
# if you want to single return with init value
|
102
|
-
# firsts = [1, 2, 3, 4]
|
103
|
-
# seconds = [4, 2, 3, 1]
|
104
|
-
# ret = [firsts, seconds].together_reduce(10){|memo, first, second|memo + first + second}
|
105
|
-
# print ret # => output 30
|
106
|
-
#
|
107
|
-
# if you want to single return with init string value
|
108
|
-
# firsts = %w{a b c}
|
109
|
-
# seconds = %w{1 2 3}
|
110
|
-
# ret = [firsts, seconds].together_reduce('start-'){|memo, first, second|memo + first + second}
|
111
|
-
# print ret # => output 'start-a1b2c3'
|
112
|
-
#
|
113
|
-
# if you want to single return with init Array value
|
114
|
-
# firsts = [1, 2, 3, 4]
|
115
|
-
# seconds = [4, 2, 3, 1]
|
116
|
-
# ret = [firsts, seconds].together_reduce([]){|memo, first, second|memo << first + second}
|
117
|
-
# print ret # => output [5, 4, 6, 5]
|
118
|
-
#
|
119
|
-
# if you want to single return with init Hash value
|
120
|
-
# firsts = [1, 2, 3, 4]
|
121
|
-
# seconds = [4, 2, 3, 1]
|
122
|
-
# ret = [firsts, seconds].together_reduce({}){|memo, first, second|memo[first] = second;memo}
|
123
|
-
# print ret # => output {1=>4, 2=>2, 3=>3, 4=>1}
|
124
|
-
def together_reduce(init = nil)
|
125
|
-
if_not_contain_array_rails_type_error
|
126
|
-
memo = initial_memo init
|
127
|
-
first.each_with_index do |i_v, i|
|
128
|
-
eval_each_str = get_args_str_for_together i
|
129
|
-
memo = instance_eval "yield(memo, #{eval_each_str})"
|
130
|
-
end
|
131
|
-
memo
|
132
|
-
end
|
133
|
-
|
134
|
-
# Arrays bulk concat.
|
135
|
-
#
|
136
|
-
# together_concat has alias :tconcat
|
137
|
-
#
|
138
|
-
# alpha = %w{one two three}
|
139
|
-
# numbers = %w{1 2 3}
|
140
|
-
# [alpha, numbers].together do |first, second|
|
141
|
-
# print "#{first}:#{second}\n" # => output one:1, two:2, three:3
|
142
|
-
# end
|
143
|
-
def together_concat(other)
|
144
|
-
if_not_contain_array_rails_type_error
|
145
|
-
each { |list|list.concat other }
|
146
|
-
end
|
147
|
-
|
148
|
-
# Arrays bulk at.
|
149
|
-
#
|
150
|
-
# together_at has alias :tat
|
151
|
-
#
|
152
|
-
# same elements size case
|
153
|
-
# alpha = %w{one two three}
|
154
|
-
# numbers = %w{1 2 3}
|
155
|
-
# [alpha, numbers].together_at 2 # => output ['three', 3]
|
156
|
-
#
|
157
|
-
# different elements size case
|
158
|
-
# alpha = %w{one two three}
|
159
|
-
# numbers = %w{1 2
|
160
|
-
# [alpha, numbers].together_at 2 # => output ['three', nil]
|
161
|
-
def together_at(index)
|
162
|
-
if_not_contain_array_rails_type_error
|
163
|
-
reduce([]) { |ats, list|ats << list.at(index) }
|
164
|
-
end
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'open_classes/object'
|
3
|
+
require 'open_classes/module'
|
4
|
+
|
5
|
+
# Array
|
6
|
+
class Array
|
7
|
+
# Arrays loop together.
|
8
|
+
#
|
9
|
+
# alpha = %w{one two three}
|
10
|
+
# numbers = %w{1 2 3}
|
11
|
+
# [alpha, numbers].together do |first, second|
|
12
|
+
# print "#{first}:#{second}\n" # => output one:1, two:2, three:3
|
13
|
+
# end
|
14
|
+
def together
|
15
|
+
if_not_contain_array_rails_type_error
|
16
|
+
first.each_with_index do |i_v, i|
|
17
|
+
eval_each_str = get_args_str_for_together i
|
18
|
+
instance_eval "yield(#{eval_each_str})"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Arrays loop together with index.
|
23
|
+
#
|
24
|
+
# alpha = %w{one two three}
|
25
|
+
# numbers = %w{1 2 3}
|
26
|
+
# [alpha, numbers].together_with_index do |first, second, index|
|
27
|
+
# print "#{index.to_s}:#{first}:#{second}\n" # => output 0:one:1, 1:two:2, 2:three:3
|
28
|
+
# end
|
29
|
+
def together_with_index
|
30
|
+
if_not_contain_array_rails_type_error
|
31
|
+
first.each_with_index do |i_v, i|
|
32
|
+
eval_each_str = get_args_str_for_together i, true
|
33
|
+
instance_eval "yield(#{eval_each_str})"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Arrays together map.
|
38
|
+
#
|
39
|
+
# together_map has aliases [:tmap, :together_collect, :tcollect]
|
40
|
+
#
|
41
|
+
# if you want to single Array return
|
42
|
+
# alpha = %w{one two three}
|
43
|
+
# numbers = %w{1 2 3}
|
44
|
+
# print [alpha, numbers].together_map do |first, second|
|
45
|
+
# "#{first}:#{second}\n"
|
46
|
+
# end # => output one:1, two:2, three:3
|
47
|
+
#
|
48
|
+
# if you want to multi Array return
|
49
|
+
# alpha = %w{one two three}
|
50
|
+
# numbers = %w{1 2 3}
|
51
|
+
# print [alpha, numbers].together_map do |first, second|
|
52
|
+
# ["#{first}:#{second}", "#{second}:#{first}"]
|
53
|
+
# end # => output [['1:one', '2:two', '3:three'], ['one:1', 'two:2', 'three:3']]
|
54
|
+
def together_map
|
55
|
+
if_not_contain_array_rails_type_error
|
56
|
+
ret = []
|
57
|
+
first.each_with_index do |i_v, i|
|
58
|
+
eval_each_str = get_args_str_for_together i
|
59
|
+
each_ret = instance_eval "yield(#{eval_each_str})"
|
60
|
+
ret = set_together_each_return_map(ret, each_ret, i)
|
61
|
+
end
|
62
|
+
ret
|
63
|
+
end
|
64
|
+
|
65
|
+
# Arrays loop together select.
|
66
|
+
#
|
67
|
+
# together_select has aliases [:tselect, :together_find_all, :tfindall]
|
68
|
+
#
|
69
|
+
# if you want to single Array return
|
70
|
+
# firsts = [1, 2, 3, 4]
|
71
|
+
# seconds = [4, 2, 3, 1]
|
72
|
+
# ret = [firsts, seconds].together_select{|first, second|first == second}
|
73
|
+
# print ret # => output [[2, 3], [2, 3]]
|
74
|
+
#
|
75
|
+
# if you want to multi Array return
|
76
|
+
# firsts = [1, 2, 3, 4]
|
77
|
+
# seconds = [4, 2, 3, 1]
|
78
|
+
# ret = [firsts, seconds].together_select{|first, second|[first.odd?, second.even?]}
|
79
|
+
# print ret # => output [[1, 3], [4, 2]]
|
80
|
+
def together_select
|
81
|
+
if_not_contain_array_rails_type_error
|
82
|
+
ret = []
|
83
|
+
first.each_with_index do |i_v, i|
|
84
|
+
eval_each_str = get_args_str_for_together i
|
85
|
+
each_ret = instance_eval "yield(#{eval_each_str})"
|
86
|
+
ret = set_together_each_return_select(ret, each_ret, i)
|
87
|
+
end
|
88
|
+
ret
|
89
|
+
end
|
90
|
+
|
91
|
+
# Arrays loop together reduce.
|
92
|
+
#
|
93
|
+
# together_reduce has aliases [:treduce, :together_inject, :tinject]
|
94
|
+
#
|
95
|
+
# if you want to single return
|
96
|
+
# firsts = [1, 2, 3, 4]
|
97
|
+
# seconds = [4, 2, 3, 1]
|
98
|
+
# ret = [firsts, seconds].together_reduce{|memo, first, second|memo + first + second}
|
99
|
+
# print ret # => output 20
|
100
|
+
#
|
101
|
+
# if you want to single return with init value
|
102
|
+
# firsts = [1, 2, 3, 4]
|
103
|
+
# seconds = [4, 2, 3, 1]
|
104
|
+
# ret = [firsts, seconds].together_reduce(10){|memo, first, second|memo + first + second}
|
105
|
+
# print ret # => output 30
|
106
|
+
#
|
107
|
+
# if you want to single return with init string value
|
108
|
+
# firsts = %w{a b c}
|
109
|
+
# seconds = %w{1 2 3}
|
110
|
+
# ret = [firsts, seconds].together_reduce('start-'){|memo, first, second|memo + first + second}
|
111
|
+
# print ret # => output 'start-a1b2c3'
|
112
|
+
#
|
113
|
+
# if you want to single return with init Array value
|
114
|
+
# firsts = [1, 2, 3, 4]
|
115
|
+
# seconds = [4, 2, 3, 1]
|
116
|
+
# ret = [firsts, seconds].together_reduce([]){|memo, first, second|memo << first + second}
|
117
|
+
# print ret # => output [5, 4, 6, 5]
|
118
|
+
#
|
119
|
+
# if you want to single return with init Hash value
|
120
|
+
# firsts = [1, 2, 3, 4]
|
121
|
+
# seconds = [4, 2, 3, 1]
|
122
|
+
# ret = [firsts, seconds].together_reduce({}){|memo, first, second|memo[first] = second;memo}
|
123
|
+
# print ret # => output {1=>4, 2=>2, 3=>3, 4=>1}
|
124
|
+
def together_reduce(init = nil)
|
125
|
+
if_not_contain_array_rails_type_error
|
126
|
+
memo = initial_memo init
|
127
|
+
first.each_with_index do |i_v, i|
|
128
|
+
eval_each_str = get_args_str_for_together i
|
129
|
+
memo = instance_eval "yield(memo, #{eval_each_str})"
|
130
|
+
end
|
131
|
+
memo
|
132
|
+
end
|
133
|
+
|
134
|
+
# Arrays bulk concat.
|
135
|
+
#
|
136
|
+
# together_concat has alias :tconcat
|
137
|
+
#
|
138
|
+
# alpha = %w{one two three}
|
139
|
+
# numbers = %w{1 2 3}
|
140
|
+
# [alpha, numbers].together do |first, second|
|
141
|
+
# print "#{first}:#{second}\n" # => output one:1, two:2, three:3
|
142
|
+
# end
|
143
|
+
def together_concat(other)
|
144
|
+
if_not_contain_array_rails_type_error
|
145
|
+
each { |list|list.concat other }
|
146
|
+
end
|
147
|
+
|
148
|
+
# Arrays bulk at.
|
149
|
+
#
|
150
|
+
# together_at has alias :tat
|
151
|
+
#
|
152
|
+
# same elements size case
|
153
|
+
# alpha = %w{one two three}
|
154
|
+
# numbers = %w{1 2 3}
|
155
|
+
# [alpha, numbers].together_at 2 # => output ['three', 3]
|
156
|
+
#
|
157
|
+
# different elements size case
|
158
|
+
# alpha = %w{one two three}
|
159
|
+
# numbers = %w{1 2}
|
160
|
+
# [alpha, numbers].together_at 2 # => output ['three', nil]
|
161
|
+
def together_at(index)
|
162
|
+
if_not_contain_array_rails_type_error
|
163
|
+
reduce([]) { |ats, list|ats << list.at(index) }
|
164
|
+
end
|
165
|
+
|
166
|
+
# Arrays bulk clear.
|
167
|
+
#
|
168
|
+
# together_clear has alias :tclear
|
169
|
+
#
|
170
|
+
# same elements size case
|
171
|
+
# alpha = %w{one two three}
|
172
|
+
# numbers = %w{1 2 3}
|
173
|
+
# [alpha, numbers].together_clear # => output [[],[]]
|
174
|
+
def together_clear
|
175
|
+
if_not_contain_array_rails_type_error
|
176
|
+
each { |list|list.clear }
|
177
|
+
end
|
178
|
+
|
179
|
+
private
|
180
|
+
|
181
|
+
def if_not_contain_array_rails_type_error
|
182
|
+
each { |f|fail TypeError, "you have to use [Array1, Array2, ...] | #{f.class} is invalid" unless f.class == Array }
|
183
|
+
end
|
184
|
+
|
185
|
+
def get_args_for_together(i)
|
186
|
+
eval_each = []
|
187
|
+
each_with_index { |j_v, j|eval_each << "self[#{j}][#{i}]" }
|
188
|
+
eval_each
|
189
|
+
end
|
190
|
+
|
191
|
+
def get_args_str_for_together(i, with_index = false)
|
192
|
+
each_eval = with_index ? get_args_for_together(i) << i : get_args_for_together(i)
|
193
|
+
each_eval.join(',')
|
194
|
+
end
|
195
|
+
|
196
|
+
def set_together_each_return_map(ret, each_ret, index)
|
197
|
+
if together_return_multi?(each_ret)
|
198
|
+
size.times { |i|ret << [] } if index == 0
|
199
|
+
(0..(size - 1)).each { |i|ret[i] << each_ret[i] }
|
200
|
+
else
|
201
|
+
ret << each_ret
|
202
|
+
end
|
203
|
+
ret
|
204
|
+
end
|
205
|
+
|
206
|
+
def set_together_each_return_select(ret, each_ret, index)
|
207
|
+
unless together_return_multi?(each_ret)
|
208
|
+
tmp_each_ret = []
|
209
|
+
size.times { tmp_each_ret << each_ret }
|
210
|
+
each_ret = tmp_each_ret
|
211
|
+
end
|
212
|
+
size.times { |i|ret << [] } if index == 0
|
213
|
+
(0..(size - 1)).each { |i|ret[i] << self[i][index] if each_ret[i] }
|
214
|
+
ret
|
215
|
+
end
|
216
|
+
|
217
|
+
def initial_memo(init)
|
218
|
+
return init unless init.nil?
|
219
|
+
first.first.is_a?(Numeric) ? 0 : first.first.is_a?(String) ? '' : nil
|
220
|
+
end
|
221
|
+
|
222
|
+
def together_return_multi?(list)
|
223
|
+
(list.class == Array && list.size == size).to_bool
|
224
|
+
end
|
225
|
+
|
226
|
+
alias_method :tconcat, :together_concat
|
227
|
+
alias_method :tat, :together_at
|
228
|
+
alias_method :tclear, :together_clear
|
229
|
+
alias_methods [:together_collect, :tmap, :tcollect], :together_map
|
230
|
+
alias_methods [:together_find_all, :tselect, :tfindall], :together_select
|
231
|
+
alias_methods [:together_inject, :treduce, :tinject], :together_reduce
|
232
|
+
end
|
data/lib/tbpgr_utils/version.rb
CHANGED
@@ -442,4 +442,50 @@ describe Array do
|
|
442
442
|
end
|
443
443
|
end
|
444
444
|
end
|
445
|
+
|
446
|
+
context :together_clear do
|
447
|
+
cases = [
|
448
|
+
{
|
449
|
+
case_no: 1,
|
450
|
+
case_title: 'valid case',
|
451
|
+
inputs: [[1, 2, 3], %w{one two three}],
|
452
|
+
method_name: :together_clear,
|
453
|
+
expected: [[], []],
|
454
|
+
},
|
455
|
+
{
|
456
|
+
case_no: 2,
|
457
|
+
case_title: 'valid case',
|
458
|
+
inputs: [[1, 2, 3], %w{one two three}],
|
459
|
+
method_name: :tclear,
|
460
|
+
expected: [[], []],
|
461
|
+
},
|
462
|
+
]
|
463
|
+
|
464
|
+
cases.each do |c|
|
465
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
466
|
+
begin
|
467
|
+
case_before c
|
468
|
+
|
469
|
+
# -- given --
|
470
|
+
# nothing
|
471
|
+
|
472
|
+
# -- when --
|
473
|
+
actual = c[:inputs].send c[:method_name]
|
474
|
+
|
475
|
+
# -- then --
|
476
|
+
expect(actual).to eq(c[:expected])
|
477
|
+
ensure
|
478
|
+
case_after c
|
479
|
+
end
|
480
|
+
end
|
481
|
+
|
482
|
+
def case_before(c)
|
483
|
+
# implement each case before
|
484
|
+
end
|
485
|
+
|
486
|
+
def case_after(c)
|
487
|
+
# implement each case after
|
488
|
+
end
|
489
|
+
end
|
490
|
+
end
|
445
491
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tbpgr_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.21
|
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: 2014-01-
|
12
|
+
date: 2014-01-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &20610228 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 4.0.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *20610228
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &20609928 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '1.3'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *20609928
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &20609700 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *20609700
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &20609364 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 2.14.1
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *20609364
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: simplecov
|
60
|
-
requirement: &
|
60
|
+
requirement: &20609064 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: 0.8.2
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *20609064
|
69
69
|
description: Utilities
|
70
70
|
email:
|
71
71
|
- tbpgr@tbpgr.jp
|