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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 273a697c87680d0c695c1617caa490bb89f7712688c60a772e109ccda91fc622
4
- data.tar.gz: c3f91ba72a275068527f0fdc9dc59026ecffacd63de1466df9a6df9b39c1104c
3
+ metadata.gz: 93dafb52f8ac98f974e664aa75c8ffec500d8e97424f4d8018632ebf2593b591
4
+ data.tar.gz: 4ebb3c134a1d4fcf498fbc1514649e072283f8f30071a8c668db7a483801e649
5
5
  SHA512:
6
- metadata.gz: 6017fee6976dbb5c9306fb783df42174bf0d88a6df33d7d4a3647f744d484358257380297970faf2c14897c506aa6b9e6dd383399f21a623e993572e50c76bf0
7
- data.tar.gz: 1f39b5c5ac1002e1596f6d9ca79c73524fce4ba574d4fec594912f4f37f14ec4e0bb53ef57d60b2b648e95c1c8d7193fa0e3b47a6262c11d882eea228c7a3509
6
+ metadata.gz: 4b89d9ba9ace8dea6e88cbefc5caf8a56ea923d2130850eee74e5fca2c888b35994841225ccf96f64bcf73eb650febefb15508704ba01f704afceb49f7efdc15
7
+ data.tar.gz: 0722b12dff36977b75f53988a1563310438ff9ed445b8d563b76fe522e5116f55b291e4bf46924611bf0b5886a71a82f53b14e915b34c0d071e3f0e6112bc06e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.1.7.3 (March 13, 2021)
2
+ - array_ext: pairwise and triplewise now support saving result in latter members []=
3
+
1
4
  ## 0.1.7.2 (February 01, 2021)
2
5
  - adding #deep_freeze to Enumerable
3
6
  - range_ext: added #mod to modify an (actually) immutable range
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.7.2
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
- each_with_index.map do |_, i|
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
- each_with_index.map do |_, i|
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.2
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-02-01 00:00:00.000000000 Z
11
+ date: 2021-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport