cotcube-helpers 0.1.7.2 → 0.1.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/VERSION +1 -1
- data/lib/cotcube-helpers/array_ext.rb +10 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93dafb52f8ac98f974e664aa75c8ffec500d8e97424f4d8018632ebf2593b591
|
4
|
+
data.tar.gz: 4ebb3c134a1d4fcf498fbc1514649e072283f8f30071a8c668db7a483801e649
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b89d9ba9ace8dea6e88cbefc5caf8a56ea923d2130850eee74e5fca2c888b35994841225ccf96f64bcf73eb650febefb15508704ba01f704afceb49f7efdc15
|
7
|
+
data.tar.gz: 0722b12dff36977b75f53988a1563310438ff9ed445b8d563b76fe522e5116f55b291e4bf46924611bf0b5886a71a82f53b14e915b34c0d071e3f0e6112bc06e
|
data/CHANGELOG.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.7.
|
1
|
+
0.1.7.3
|
@@ -29,28 +29,32 @@ class Array
|
|
29
29
|
# This method iterates over an Array by calling the given block on all 2 consecutive elements
|
30
30
|
# it returns a Array of self.size - 1
|
31
31
|
#
|
32
|
-
def pairwise(&block)
|
32
|
+
def pairwise(ret=nil, &block)
|
33
33
|
raise ArgumentError, 'Array.one_by_one needs an arity of 2 (i.e. |a, b|)' unless block.arity == 2
|
34
|
+
raise ArgumentError, 'Each element of Array should respond to []=, at least the last one fails.' unless self.last.respond_to?(:[]=)
|
34
35
|
return [] if size <= 1
|
35
36
|
|
36
|
-
|
37
|
+
each_index.map do |i|
|
37
38
|
next if i.zero?
|
38
39
|
|
39
|
-
block.call(self[i - 1], self[i])
|
40
|
+
r = block.call(self[i - 1], self[i])
|
41
|
+
ret.nil? ? r : (self[i][ret] = r)
|
40
42
|
end.compact
|
41
43
|
end
|
42
44
|
|
43
45
|
alias one_by_one pairwise
|
44
46
|
|
45
47
|
# same as pairwise, but with arity of three
|
46
|
-
def triplewise(&block)
|
48
|
+
def triplewise(ret=nil, &block)
|
47
49
|
raise ArgumentError, 'Array.triplewise needs an arity of 3 (i.e. |a, b, c|)' unless block.arity == 3
|
50
|
+
raise ArgumentError, 'Each element of Array should respond to []=, at least the last one fails. unless self.last.respond_to?(:[]=)
|
48
51
|
return [] if size <= 2
|
49
52
|
|
50
|
-
|
53
|
+
each_index.map do |i|
|
51
54
|
next if i < 2
|
52
55
|
|
53
|
-
block.call(self[i - 2], self[i - 1], self[i])
|
56
|
+
r = block.call(self[i - 2], self[i - 1], self[i])
|
57
|
+
ret.nil? ? r : (self[i][ret] = r)
|
54
58
|
end.compact
|
55
59
|
end
|
56
60
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cotcube-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.7.
|
4
|
+
version: 0.1.7.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin L. Tischendorf
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|