flex_array 0.3.2 → 0.3.7
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.
- checksums.yaml +5 -5
- data/.gitignore +0 -15
- data/.reek.yml +17 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/README.md +67 -0
- data/bench/benchmark.rb +243 -0
- data/bench/results.txt +97 -0
- data/flex_array.gemspec +6 -10
- data/irbt.rb +18 -0
- data/lib/flex_array.rb +13 -30
- data/lib/flex_array/array.rb +9 -24
- data/lib/flex_array/flex_array_append.rb +4 -23
- data/lib/flex_array/flex_array_each.rb +33 -208
- data/lib/flex_array/flex_array_forever.rb +6 -4
- data/lib/flex_array/flex_array_index.rb +4 -29
- data/lib/flex_array/flex_array_new.rb +9 -56
- data/lib/flex_array/flex_array_process.rb +23 -63
- data/lib/flex_array/flex_array_reshape.rb +13 -23
- data/lib/flex_array/flex_array_transpose.rb +7 -16
- data/lib/flex_array/flex_array_validate.rb +6 -15
- data/lib/flex_array/integer.rb +4 -13
- data/lib/flex_array/object.rb +4 -13
- data/lib/flex_array/range.rb +4 -13
- data/lib/flex_array/spec_array.rb +5 -9
- data/lib/flex_array/spec_component.rb +14 -22
- data/lib/flex_array/version.rb +1 -2
- data/rakefile.rb +1 -24
- data/reek.txt +9 -2
- data/tests/array_test.rb +0 -4
- data/tests/flex_array_append_test.rb +0 -23
- data/tests/flex_array_each_test.rb +483 -487
- data/tests/flex_array_index_test.rb +0 -4
- data/tests/flex_array_new_test.rb +0 -4
- data/tests/flex_array_reshape_test.rb +4 -4
- data/tests/flex_array_test.rb +0 -4
- data/tests/flex_array_transpose_test.rb +0 -4
- data/tests/flex_array_validate_test.rb +5 -4
- data/tests/integer_test.rb +0 -4
- data/tests/object_test.rb +0 -4
- data/tests/range_test.rb +0 -4
- data/tests/spec_array_test.rb +0 -4
- data/tests/spec_component_test.rb +0 -4
- metadata +19 -49
- data/docs/Flex_Array_UG.odt +0 -0
- data/docs/Flex_Array_UG_Version_0_3_0.pdf +0 -0
- data/flex_array.reek +0 -109
- data/readme.txt +0 -2
- data/sire.rb +0 -82
data/flex_array.gemspec
CHANGED
@@ -13,25 +13,21 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.version = FlexArray::VERSION
|
14
14
|
s.author = ["Peter Camilleri"]
|
15
15
|
s.email = "peter.c.camilleri@gmail.com"
|
16
|
-
s.homepage = "
|
16
|
+
s.homepage = "https://github.com/PeterCamilleri/flex_array"
|
17
17
|
s.platform = Gem::Platform::RUBY
|
18
18
|
s.required_ruby_version = '>=1.9.3'
|
19
19
|
|
20
|
-
s.add_development_dependency "bundler", "
|
21
|
-
s.add_development_dependency 'rake'
|
22
|
-
s.add_development_dependency 'reek', "~>
|
20
|
+
s.add_development_dependency "bundler", ">= 2.1.0"
|
21
|
+
s.add_development_dependency 'rake', ">= 12.3.3"
|
22
|
+
s.add_development_dependency 'reek', "~> 5.0.2"
|
23
23
|
s.add_development_dependency 'minitest', "~> 4.7.5"
|
24
|
-
s.add_development_dependency 'rdoc', "~> 4.0.1"
|
25
|
-
s.add_development_dependency 'minitest_visible', ">= 0.1.0"
|
26
24
|
|
27
25
|
s.add_runtime_dependency 'in_array'
|
28
26
|
|
29
|
-
s.files = `git ls-files`.split($/)
|
30
|
-
s.
|
31
|
-
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
27
|
+
s.files = `git ls-files`.split($/).select {|f| f !~ /^docs\//}
|
28
|
+
s.test_files = s.files.grep(%r{^(test)/})
|
32
29
|
|
33
30
|
s.license = 'MIT'
|
34
|
-
s.has_rdoc = true
|
35
31
|
s.require_paths = ["lib"]
|
36
32
|
end
|
37
33
|
|
data/irbt.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# An IRB + flex array Test bed
|
3
|
+
|
4
|
+
require 'irb'
|
5
|
+
|
6
|
+
puts "Starting an IRB console with flex array loaded."
|
7
|
+
|
8
|
+
if ARGV[0] == 'local'
|
9
|
+
require_relative 'lib/flex_array'
|
10
|
+
puts "flex_array loaded locally: #{FlexArray::VERSION}"
|
11
|
+
|
12
|
+
ARGV.shift
|
13
|
+
else
|
14
|
+
require 'flex_array'
|
15
|
+
puts "flex_array loaded from gem: #{FlexArray::VERSION}"
|
16
|
+
end
|
17
|
+
|
18
|
+
IRB.start
|
data/lib/flex_array.rb
CHANGED
@@ -19,79 +19,62 @@ require_relative 'flex_array/flex_array_each'
|
|
19
19
|
require_relative 'flex_array/flex_array_validate'
|
20
20
|
require_relative 'flex_array/flex_array_process'
|
21
21
|
|
22
|
-
|
23
|
-
#* flex_array.rb - The root file that gathers up all the flex array parts.
|
22
|
+
# A flexible array class.
|
24
23
|
class FlexArray
|
25
24
|
include InArrayAlready
|
26
25
|
|
27
|
-
#The version of this class.
|
28
|
-
#<br>Returns
|
29
|
-
#* A version string; <major>.<minor>.<step>
|
26
|
+
# The version of this class. "<major>.<minor>.<step>"
|
30
27
|
def self.version
|
31
28
|
FlexArray::VERSION
|
32
29
|
end
|
33
30
|
|
34
|
-
#The version of the class of this instance.
|
35
|
-
#<br>Returns
|
36
|
-
#* A version string; <major>.<minor>.<step>
|
31
|
+
# The version of the class of this instance.
|
37
32
|
def version
|
38
33
|
FlexArray::VERSION
|
39
34
|
end
|
40
35
|
|
41
|
-
#The array specifications. An array of spec components.
|
36
|
+
# The array specifications. An array of spec components.
|
42
37
|
attr_accessor :array_specs
|
43
38
|
|
44
|
-
#The underlying array data used by the flex array.
|
39
|
+
# The underlying array data used by the flex array.
|
45
40
|
attr_accessor :array_data
|
46
41
|
|
47
|
-
#The total number of elements in this array.
|
42
|
+
# The total number of elements in this array.
|
48
43
|
def length
|
49
44
|
@array_specs.spec_count
|
50
45
|
end
|
51
46
|
|
52
47
|
alias size length
|
53
48
|
|
54
|
-
#The number of dimensions in this array.
|
49
|
+
# The number of dimensions in this array.
|
55
50
|
def dimensions
|
56
51
|
@array_specs.spec_dimensions
|
57
52
|
end
|
58
53
|
|
59
|
-
#Is this flex array transposed?
|
54
|
+
# Is this flex array transposed?
|
60
55
|
attr_reader :transposed
|
61
56
|
|
62
|
-
#Get the limits of the subscripts of the flex array.
|
57
|
+
# Get the limits of the subscripts of the flex array.
|
63
58
|
def limits
|
64
59
|
@array_specs.collect {|spec| spec.range }
|
65
60
|
end
|
66
61
|
|
67
|
-
#Return this flex array as a flex array!
|
68
|
-
#<br>Returns
|
69
|
-
#* A flex array -- self
|
62
|
+
# Return this flex array as a flex array!
|
70
63
|
def to_flex_array
|
71
64
|
self
|
72
65
|
end
|
73
66
|
|
74
|
-
#Are these FlexArrays equal?
|
75
|
-
#<br>Parameters
|
76
|
-
#* other - The object being tested for equality.
|
77
|
-
#<br>Returns
|
78
|
-
#* true if the flex arrays are equal shape and data.
|
67
|
+
# Are these FlexArrays equal?
|
79
68
|
def ==(other)
|
80
69
|
self.compatible?(other) && @array_data == other.array_data
|
81
70
|
end
|
82
71
|
|
83
|
-
#Make FlexArrays comparable.
|
84
|
-
#<br>Parameters
|
85
|
-
#* other - The object being tested for compariositality.
|
86
|
-
#<br>Returns
|
87
|
-
#* 1 if self > other
|
88
|
-
#* 0 if self = other
|
89
|
-
#* -1 if self < other
|
72
|
+
# Make FlexArrays comparable with the compariositality method.
|
90
73
|
def <=>(other)
|
91
74
|
@array_data <=> other.array_data
|
92
75
|
end
|
93
76
|
|
94
|
-
#Is this flex array empty?
|
77
|
+
# Is this flex array empty?
|
95
78
|
def empty?
|
96
79
|
length == 0
|
97
80
|
end
|
data/lib/flex_array/array.rb
CHANGED
@@ -1,33 +1,22 @@
|
|
1
|
-
#Extensions to Array needed to support flex array.
|
1
|
+
# Extensions to Array needed to support flex array.
|
2
|
+
|
2
3
|
class Array
|
3
|
-
#Get the specifications of the array index values.
|
4
|
-
#<br>Returns
|
5
|
-
#* An array with one range in it.
|
4
|
+
# Get the specifications of the array index values.
|
6
5
|
def limits
|
7
6
|
[0...self.length]
|
8
7
|
end
|
9
8
|
|
10
|
-
#Quick access to the limits for internal use.
|
11
|
-
#<br>Returns
|
12
|
-
#* An array with one spec component in it.
|
9
|
+
# Quick access to the limits for internal use.
|
13
10
|
def array_specs
|
14
11
|
SpecArray.new([0...self.length])
|
15
12
|
end
|
16
13
|
|
17
|
-
#Quick access to the array data for internal use.
|
18
|
-
#<br>Returns
|
19
|
-
#* An array -- self
|
14
|
+
# Quick access to the array data for internal use.
|
20
15
|
def array_data
|
21
16
|
self
|
22
17
|
end
|
23
18
|
|
24
|
-
#Convert this array to an range index against the spec.
|
25
|
-
#<br>Parameters
|
26
|
-
#* spec - The spec component used to validate this index.
|
27
|
-
#<br>Returns
|
28
|
-
#* A range.
|
29
|
-
#<br>Exceptions
|
30
|
-
#* IndexError if the range is not valid.
|
19
|
+
# Convert this array to an range index against the spec.
|
31
20
|
def to_index_range(spec)
|
32
21
|
spec_max = spec.max
|
33
22
|
|
@@ -43,13 +32,9 @@ class Array
|
|
43
32
|
end
|
44
33
|
end
|
45
34
|
|
46
|
-
#Return this flex array as a flex array!
|
47
|
-
#<br>Returns
|
48
|
-
#* A flex array that references this array.
|
49
|
-
#<br>Note
|
50
|
-
#* To avoid a shared reference, use my_array.dup.to_flex_array or
|
51
|
-
# FlexArray.new_from_array(my_array.dup) instead.
|
35
|
+
# Return this flex array as a flex array!
|
52
36
|
def to_flex_array
|
53
37
|
FlexArray.new_from_array(self)
|
54
38
|
end
|
55
|
-
|
39
|
+
|
40
|
+
end
|
@@ -1,12 +1,7 @@
|
|
1
|
-
|
1
|
+
# Append method support for the flex array.
|
2
|
+
|
2
3
|
class FlexArray
|
3
|
-
#Append to the flex array.
|
4
|
-
#<br>Parameters
|
5
|
-
#* data - the data being appended to this array.
|
6
|
-
#<br>Returns
|
7
|
-
#* The array spec of the array being appended.
|
8
|
-
#<br>Exceptions
|
9
|
-
#* ArgumentError if the data may not be appended.
|
4
|
+
# Append to the flex array.
|
10
5
|
def << (data)
|
11
6
|
fail "Cannot append to a transposed array." if @transposed
|
12
7
|
specs = get_append_specs(data = data.in_array)
|
@@ -15,22 +10,8 @@ class FlexArray
|
|
15
10
|
self
|
16
11
|
end
|
17
12
|
|
18
|
-
#Make a copy of the other's data.
|
19
|
-
#<br>Parameters
|
20
|
-
#* other - The flex array whose data is to be copied.
|
21
|
-
def copy_data(other)
|
22
|
-
fail ArgumentError, "Incompatible data copy." unless compatible?(other)
|
23
|
-
@array_data = other.array_data.dup
|
24
|
-
end
|
25
|
-
|
26
13
|
private
|
27
|
-
#Extract and validate the append array_spec
|
28
|
-
#<br>Parameters
|
29
|
-
#* data - the data being appended to this array.
|
30
|
-
#<br>Returns
|
31
|
-
#* The array spec of the array being appended.
|
32
|
-
#<br>Exceptions
|
33
|
-
#* ArgumentError if the data may not be appended.
|
14
|
+
# Extract and validate the append array_spec
|
34
15
|
def get_append_specs(data)
|
35
16
|
spec_len = (specs = data.array_specs).length
|
36
17
|
|
@@ -1,21 +1,9 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# Support for each and related methods for the flex array.
|
2
|
+
|
3
3
|
class FlexArray
|
4
4
|
include Enumerable
|
5
5
|
|
6
|
-
#Retrieve data from the array endlessly repeating as needed.
|
7
|
-
#<br>Parameters
|
8
|
-
#* count - The number of times to cycle through the flex array. Defaults to
|
9
|
-
# cycling forever.
|
10
|
-
#* block - The optional block to be executed for each selected array element.
|
11
|
-
# The return value is the last value returned by the block. If the block
|
12
|
-
# is not present, then an enumerator object is returned.
|
13
|
-
#<br>Returns
|
14
|
-
#* nil or an enumerator if no block is provided.
|
15
|
-
#<br>Block Arguments
|
16
|
-
#* value - Each value selected by the iteration.
|
17
|
-
#<br>Endemic Code Smells
|
18
|
-
#* :reek:NestedIterators
|
6
|
+
# Retrieve data from the array endlessly repeating as needed.
|
19
7
|
def cycle(count = FOREVER, &block)
|
20
8
|
if block_given?
|
21
9
|
if @transposed && length > 0
|
@@ -34,22 +22,7 @@ class FlexArray
|
|
34
22
|
end
|
35
23
|
end
|
36
24
|
|
37
|
-
#Retrieve data from a subset of the flex array endlessly repeating as needed.
|
38
|
-
#<br>Parameters
|
39
|
-
#* indexes - An array with as many entries as the flexible array has
|
40
|
-
# dimensions. See [] for more details. Note that since indexes is NOT
|
41
|
-
# a splat parameter, it must be passed as an array explicitly.
|
42
|
-
#* count - The number of times to cycle through the flex array. Defaults to
|
43
|
-
# cycling forever.
|
44
|
-
#* block - The optional block to be executed for each selected array element.
|
45
|
-
# The return value is the last value returned by the block. If the block
|
46
|
-
# is not present, then an enumerator object is returned.
|
47
|
-
#<br>Returns
|
48
|
-
#* nil or an enumerator if no block is provided.
|
49
|
-
#<br>Block Arguments
|
50
|
-
#* value - Each value selected by the iteration.
|
51
|
-
#<br>Endemic Code Smells
|
52
|
-
#* :reek:NestedIterators
|
25
|
+
# Retrieve data from a subset of the flex array endlessly repeating as needed.
|
53
26
|
def select_cycle(indexes, count = FOREVER, &block)
|
54
27
|
validate_index_count(indexes)
|
55
28
|
|
@@ -68,14 +41,7 @@ class FlexArray
|
|
68
41
|
end
|
69
42
|
end
|
70
43
|
|
71
|
-
#Process the standard each operator.
|
72
|
-
#<br>Parameters
|
73
|
-
#* block - The optional block to be executed for each selected array element.
|
74
|
-
#<br>Returns
|
75
|
-
#* If the block is not present, then an enumerator object is returned.
|
76
|
-
# Otherwise the flex array is returned.
|
77
|
-
#<br>Block Arguments
|
78
|
-
#* value - Each value selected by the iteration.
|
44
|
+
# Process the standard each operator.
|
79
45
|
def each(&block)
|
80
46
|
if block_given?
|
81
47
|
if @transposed
|
@@ -90,17 +56,7 @@ class FlexArray
|
|
90
56
|
end
|
91
57
|
end
|
92
58
|
|
93
|
-
#Process the enhanced select_each operator.
|
94
|
-
#<br>Parameters
|
95
|
-
#* indexes - An array with as many entries as the flexible array has
|
96
|
-
# dimensions. See [] for more details. Note that since indexes is NOT
|
97
|
-
# a splat parameter, it must be passed as an array explicitly
|
98
|
-
#* block - The optional block to be executed for each selected array element.
|
99
|
-
#<br>Returns
|
100
|
-
#* If the block is not present, then an enumerator object is returned.
|
101
|
-
# Otherwise the flex array is returned.
|
102
|
-
#<br>Block Arguments
|
103
|
-
#* value - Each value selected by the iteration.
|
59
|
+
# Process the enhanced select_each operator.
|
104
60
|
def select_each(indexes, &block)
|
105
61
|
validate_index_count(indexes)
|
106
62
|
|
@@ -112,15 +68,7 @@ class FlexArray
|
|
112
68
|
end
|
113
69
|
end
|
114
70
|
|
115
|
-
#Process the standard each_with_index operator.
|
116
|
-
#<br>Parameters
|
117
|
-
#* block - The optional block to be executed for each selected array element.
|
118
|
-
#<br>Returns
|
119
|
-
#* If the block is not present, then an enumerator object is returned.
|
120
|
-
# Otherwise the flex array is returned.
|
121
|
-
#<br>Block Arguments
|
122
|
-
#* value - Each value selected by the iteration.
|
123
|
-
#* index - An array with the full index of the selected value.
|
71
|
+
# Process the standard each_with_index operator.
|
124
72
|
def each_with_index(&block)
|
125
73
|
if block_given?
|
126
74
|
process_all {|index, posn| block.call(@array_data[posn], index)}
|
@@ -130,18 +78,7 @@ class FlexArray
|
|
130
78
|
end
|
131
79
|
end
|
132
80
|
|
133
|
-
#Process the enhanced select_each_with_index operator.
|
134
|
-
#<br>Parameters
|
135
|
-
#* indexes - An array with as many entries as the flexible array has
|
136
|
-
# dimensions. See [] for more details. Note that since indexes is NOT
|
137
|
-
# a splat parameter, it must be passed as an array explicitly.
|
138
|
-
#* block - The optional block to be executed for each selected array element.
|
139
|
-
#<br>Returns
|
140
|
-
#* If the block is not present, then an enumerator object is returned.
|
141
|
-
# Otherwise the flex array is returned.
|
142
|
-
#<br>Block Arguments
|
143
|
-
#* value - Each value selected by the iteration.
|
144
|
-
#* index - An array with the full index of the selected value.
|
81
|
+
# Process the enhanced select_each_with_index operator.
|
145
82
|
def select_each_with_index(indexes, &block)
|
146
83
|
validate_index_count(indexes)
|
147
84
|
|
@@ -153,18 +90,8 @@ class FlexArray
|
|
153
90
|
end
|
154
91
|
end
|
155
92
|
|
156
|
-
#A specialized each variant that passes the low level data, the index
|
157
|
-
#and the position to the block.
|
158
|
-
#<br>Parameters
|
159
|
-
#* block - The optional block to be executed for each selected array element.
|
160
|
-
# The return value is the last value returned by the block. If the block
|
161
|
-
# is not present, then an enumerator object is returned.
|
162
|
-
#<br>Returns
|
163
|
-
#* If the block is not present, then an enumerator object is returned.
|
164
|
-
# Otherwise the flex array is returned.
|
165
|
-
#<br>Block Arguments
|
166
|
-
#* index - An array with the full index of the selected value.
|
167
|
-
#* posn - The position of the data in the low level data store.
|
93
|
+
# A specialized each variant that passes the low level data, the index
|
94
|
+
# and the position to the block.
|
168
95
|
def _each_raw(&block)
|
169
96
|
if block_given?
|
170
97
|
process_all {|index, posn| block.call(index, posn)}
|
@@ -174,21 +101,8 @@ class FlexArray
|
|
174
101
|
end
|
175
102
|
end
|
176
103
|
|
177
|
-
#An enhanced specialized each variant that passes the low level data,
|
178
|
-
#the index and the position to the block.
|
179
|
-
#<br>Parameters
|
180
|
-
#* indexes - An array with as many entries as the flexible array has
|
181
|
-
# dimensions. See [] for more details. Note that since indexes is NOT
|
182
|
-
# a splat parameter, it must be passed as an array explicitly.
|
183
|
-
#* block - The optional block to be executed for each selected array element.
|
184
|
-
# The return value is the last value returned by the block. If the block
|
185
|
-
# is not present, then an enumerator object is returned.
|
186
|
-
#<br>Returns
|
187
|
-
#* If the block is not present, then an enumerator object is returned.
|
188
|
-
# Otherwise the flex array is returned.
|
189
|
-
#<br>Block Arguments
|
190
|
-
#* index - An array with the full index of the selected value.
|
191
|
-
#* posn - The position of the data in the low level data store.
|
104
|
+
# An enhanced specialized each variant that passes the low level data,
|
105
|
+
# the index and the position to the block.
|
192
106
|
def _select_each_raw(indexes, &block)
|
193
107
|
validate_index_count(indexes)
|
194
108
|
|
@@ -202,47 +116,21 @@ class FlexArray
|
|
202
116
|
|
203
117
|
alias_method :flatten_collect, :collect
|
204
118
|
|
205
|
-
#The flex array version of collect that returns a flex array.
|
206
|
-
#<br>Parameters
|
207
|
-
#* block - The optional block to be executed for each selected array element.
|
208
|
-
#<br>Returns
|
209
|
-
#* An array of the computed objects retuned by the block.
|
210
|
-
#<br>Block Arguments
|
211
|
-
#* value - Each value selected by the iteration.
|
119
|
+
# The flex array version of collect that returns a flex array.
|
212
120
|
def collect(&block)
|
213
121
|
result = self.dup
|
214
122
|
result.collect!(&block)
|
215
123
|
end
|
216
124
|
|
217
|
-
#The flex array version of collect that accepts an optional set of indexes
|
218
|
-
#to select the data being collected into a flex array.
|
219
|
-
#<br>Parameters
|
220
|
-
#* indexes - An array with as many entries as the flexible array has
|
221
|
-
# dimensions. See [] for more details. Note that since indexes is NOT
|
222
|
-
# a splat parameter, it must be passed as an array explicitly.
|
223
|
-
#* block - The optional block to be executed for each selected array element.
|
224
|
-
#<br>Returns
|
225
|
-
#* An array of the computed objects retuned by the block.
|
226
|
-
# If the block is not present, an enumerator object is returned.
|
227
|
-
#<br>Block Arguments
|
228
|
-
#* value - Each value selected by the iteration.
|
125
|
+
# The flex array version of collect that accepts an optional set of indexes
|
126
|
+
# to select the data being collected into a flex array.
|
229
127
|
def select_collect(indexes, &block)
|
230
128
|
result = self.dup
|
231
129
|
result.select_collect!(indexes, &block)
|
232
130
|
end
|
233
131
|
|
234
|
-
#The flex array version of collect that accepts an optional set of indexes
|
235
|
-
#to select the data being collected into a standard array.
|
236
|
-
#<br>Parameters
|
237
|
-
#* indexes - An array with as many entries as the flexible array has
|
238
|
-
# dimensions. See [] for more details. Note that since indexes is NOT
|
239
|
-
# a splat parameter, it must be passed as an array explicitly.
|
240
|
-
#* block - The optional block to be executed for each selected array element.
|
241
|
-
#<br>Returns
|
242
|
-
#* An array of the computed objects retuned by the block.
|
243
|
-
# If the block is not present, an enumerator object is returned.
|
244
|
-
#<br>Block Arguments
|
245
|
-
#* value - Each value selected by the iteration.
|
132
|
+
# The flex array version of collect that accepts an optional set of indexes
|
133
|
+
# to select the data being collected into a standard array.
|
246
134
|
def select_flatten_collect(indexes, &block)
|
247
135
|
validate_index_count(indexes)
|
248
136
|
|
@@ -255,15 +143,7 @@ class FlexArray
|
|
255
143
|
end
|
256
144
|
end
|
257
145
|
|
258
|
-
#The flex array version of collect!
|
259
|
-
#<br>Parameters
|
260
|
-
#* block - The *required* block to be executed for each selected array element.
|
261
|
-
# The return value is the last value returned by the block. If the block
|
262
|
-
# is not present, an enumerator object is returned.
|
263
|
-
#<br>Returns
|
264
|
-
#* self
|
265
|
-
#<br>Block Arguments
|
266
|
-
#* value - Each value selected by the iteration.
|
146
|
+
# The flex array version of collect!
|
267
147
|
def collect!(&block)
|
268
148
|
fail ArgumentError, "A block is required." unless block_given?
|
269
149
|
|
@@ -277,19 +157,8 @@ class FlexArray
|
|
277
157
|
self
|
278
158
|
end
|
279
159
|
|
280
|
-
#The enhanced flex array version of collect! that accepts a set of indexes
|
281
|
-
#to select the data being collected.
|
282
|
-
#<br>Parameters
|
283
|
-
#* indexes - An array with as many entries as the flexible array has
|
284
|
-
# dimensions. See [] for more details. Note that since indexes is NOT
|
285
|
-
# a splat parameter, it must be passed as an array explicitly.
|
286
|
-
#* block - The *required* block to be executed for each selected array element.
|
287
|
-
# The return value is the last value returned by the block. If the block
|
288
|
-
# is not present, an enumerator object is returned.
|
289
|
-
#<br>Returns
|
290
|
-
#* self
|
291
|
-
#<br>Block Arguments
|
292
|
-
#* value - Each value selected by the iteration.
|
160
|
+
# The enhanced flex array version of collect! that accepts a set of indexes
|
161
|
+
# to select the data being collected.
|
293
162
|
def select_collect!(indexes, &block)
|
294
163
|
fail ArgumentError, "A block is required." unless block_given?
|
295
164
|
validate_index_count(indexes)
|
@@ -300,17 +169,9 @@ class FlexArray
|
|
300
169
|
self
|
301
170
|
end
|
302
171
|
|
303
|
-
#The flex array version of find_index. This returns the
|
304
|
-
#
|
305
|
-
#
|
306
|
-
#<br>Parameters
|
307
|
-
#* object - The optional value to search for.
|
308
|
-
#* block - The optional block to be executed for each selected array element.
|
309
|
-
# If the block or object are not present, an enumerator object is returned.
|
310
|
-
#<br>Returns
|
311
|
-
#* The index of the first place that matched or nil if none matched.
|
312
|
-
#<br>Block Arguments
|
313
|
-
#* value - Each value selected by the iteration.
|
172
|
+
# The flex array version of find_index. This returns the coordinates of the
|
173
|
+
# first object that matches the search object or is flagged true by the
|
174
|
+
# search block.
|
314
175
|
def find_index(value = nil, &block)
|
315
176
|
blk = get_find_block(value, &block)
|
316
177
|
|
@@ -327,20 +188,9 @@ class FlexArray
|
|
327
188
|
end
|
328
189
|
end
|
329
190
|
|
330
|
-
#The enhanced flex array version of find_index. This returns the
|
331
|
-
#
|
332
|
-
#
|
333
|
-
#<br>Parameters
|
334
|
-
#* indexes - An array with as many entries as the flexible array has
|
335
|
-
# dimensions. See [] for more details. Note that since indexes is NOT
|
336
|
-
# a splat parameter, it must be passed as an array explicitly.
|
337
|
-
#* object - The optional value to search for.
|
338
|
-
#* block - The optional block to be executed for each selected array element.
|
339
|
-
# If the block or object are not present, an enumerator object is returned.
|
340
|
-
#<br>Returns
|
341
|
-
#* The index of the first place that matched or nil if none matched.
|
342
|
-
#<br>Block Arguments
|
343
|
-
#* value - Each value selected by the iteration.
|
191
|
+
# The enhanced flex array version of find_index. This returns the coordinates
|
192
|
+
# of the first object that matches the search object or is flagged true by
|
193
|
+
# the search block.
|
344
194
|
def select_find_index(indexes, value = nil, &block)
|
345
195
|
validate_index_count(indexes)
|
346
196
|
blk = get_find_block(value, &block)
|
@@ -358,17 +208,9 @@ class FlexArray
|
|
358
208
|
end
|
359
209
|
end
|
360
210
|
|
361
|
-
#The improved flex array version of find_index. This returns the
|
362
|
-
#
|
363
|
-
#
|
364
|
-
#<br>Parameters
|
365
|
-
#* object - The optional value to search for.
|
366
|
-
#* block - The optional block to be executed for each selected array element.
|
367
|
-
# If the block or object are not present, an enumerator object is returned.
|
368
|
-
#<br>Returns
|
369
|
-
#* An array of the indexes of the places that matched.
|
370
|
-
#<br>Block Arguments
|
371
|
-
#* value - Each value selected by the iteration.
|
211
|
+
# The improved flex array version of find_index. This returns the coordinates
|
212
|
+
# of objects that match the search object or are flagged true by the search
|
213
|
+
# block.
|
372
214
|
def find_indexes(value = nil, &block)
|
373
215
|
blk, result = get_find_block(value, &block), []
|
374
216
|
|
@@ -385,20 +227,9 @@ class FlexArray
|
|
385
227
|
end
|
386
228
|
end
|
387
229
|
|
388
|
-
#The enhanced and improved flex array version of find_index. This returns
|
389
|
-
#coordinates of objects that match the search object or are
|
390
|
-
#
|
391
|
-
#<br>Parameters
|
392
|
-
#* indexes - An array with as many entries as the flexible array has
|
393
|
-
# dimensions. See [] for more details. Note that since indexes is NOT
|
394
|
-
# a splat parameter, it must be passed as an array explicitly.
|
395
|
-
#* object - The optional value to search for.
|
396
|
-
#* block - The optional block to be executed for each selected array element.
|
397
|
-
# If the block or object are not present, an enumerator object is returned.
|
398
|
-
#<br>Returns
|
399
|
-
#* An array of the indexes of the places that matched.
|
400
|
-
#<br>Block Arguments
|
401
|
-
#* value - Each value selected by the iteration.
|
230
|
+
# The enhanced and improved flex array version of find_index. This returns
|
231
|
+
# the coordinates of objects that match the search object or are flagged true
|
232
|
+
# by the search block.
|
402
233
|
def select_find_indexes(indexes, value = nil, &block)
|
403
234
|
validate_index_count(indexes)
|
404
235
|
blk, result = get_find_block(value, &block), []
|
@@ -418,16 +249,10 @@ class FlexArray
|
|
418
249
|
|
419
250
|
private
|
420
251
|
|
421
|
-
#A helper method to determine which block to use in the find_index family.
|
422
|
-
#<br>Returns
|
423
|
-
#* The block to use or nil.
|
424
|
-
#<br>Endemic Code Smells
|
425
|
-
#* :reek:NilCheck
|
252
|
+
# A helper method to determine which block to use in the find_index family.
|
426
253
|
def get_find_block(value, &block)
|
427
254
|
if block_given?
|
428
255
|
block
|
429
|
-
elsif value.nil?
|
430
|
-
nil
|
431
256
|
else
|
432
257
|
lambda {|obj| obj == value }
|
433
258
|
end
|