refinements 9.6.0 → 9.7.1

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: 5c0144180dd3a5cabe861b385cd0c766eaf54280ca6812dc6e82db4e564ce6c0
4
- data.tar.gz: b339710c168c98fffbe5b1994031f033041c9f6c16b0df96555cb80fd5cd7269
3
+ metadata.gz: 0dbec0b903b2ce6a78545bf34285ab60d20fd1b511975c750829a883107de915
4
+ data.tar.gz: 14c0fa259be4dd70fcc3766bcf745b9c267af3b1a58c0f32fc0f1fdfbb9d6458
5
5
  SHA512:
6
- metadata.gz: 926090205f29ac111494e00e7de37b59b8549c6f979c8a0d62d852e9d87193093073ac0f005564243fc472eacf4de68f62bea8b1d45f3f363e113805758f726d
7
- data.tar.gz: 22a524d073a48922d6347119f01f4c059bbd2bba8f65a2e6573951b137b772dc3f7797a3596ccb850bb63159a9b2ab501bb334f7ac8a80f66ca93f55886bdb09
6
+ metadata.gz: 0bdd1ea6074fd07ae02659c283a1a035da4695d5375150264eea4e88ca5eae7b041a41ea6a14384305143695752fd6c1397477be387a28e75d39f80c907c8f87
7
+ data.tar.gz: 0caa5d7b26ad27a5378daad28b9a0cc7c7bc6c6f0d5db5d3fc2f20cacc0a834ae902269b74432196df89b90510d918afa60a941ae19254cb6bf0eecc46fec8f8
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -278,6 +278,30 @@ example.ring { |(before, current, after)| puts "#{before} #{current} #{after}" }
278
278
  # [2 3 1]
279
279
  ----
280
280
 
281
+ ===== #supplant
282
+
283
+ Answers mutated array where first target element found is replaced by single or multiple elements.
284
+
285
+ [source,ruby]
286
+ ----
287
+ %i[a b a].supplant :a, :z # [:z, :b, :a]
288
+ %i[a b a].supplant :a, :z, :y # [:z, :y, :b, :a]
289
+ %i[a b a].supplant :a, %i[z y] # [[:z, :y], :b, :a]
290
+ ----
291
+
292
+ ===== #supplant_if
293
+
294
+ Answers mutated array where all target elements are replaced by single or multiple elements.
295
+
296
+ ⚠️ Be aware that this can be an expensive operation on large arrays.
297
+
298
+ [source,ruby]
299
+ ----
300
+ %i[a b a].supplant_if :a, :z # [:z, :b, :z]
301
+ %i[a b a].supplant_if :a, :z, :y # [:z, :y, :b, :z, :y]
302
+ %i[a b a].supplant_if :a, %i[z y] # [[:z, :y], :b, [:z, :y]]
303
+ ----
304
+
281
305
  ===== #to_sentence
282
306
 
283
307
  Answers a sentence using `", "` as the default delimiter and `"and"` as the default conjunction.
@@ -1346,7 +1370,7 @@ To contribute, run:
1346
1370
 
1347
1371
  [source,bash]
1348
1372
  ----
1349
- git clone https://github.com/bkuhlmann/refinements.git
1373
+ git clone https://github.com/bkuhlmann/refinements
1350
1374
  cd refinements
1351
1375
  bin/setup
1352
1376
  ----
@@ -35,6 +35,20 @@ module Refinements
35
35
 
36
36
  def ring(&) = [last, *self, first].each_cons(3, &)
37
37
 
38
+ def supplant target, *replacements
39
+ index(target).then do |position|
40
+ delete_at position
41
+ insert position, *replacements
42
+ end
43
+
44
+ self
45
+ end
46
+
47
+ def supplant_if target, *replacements
48
+ each { |item| supplant target, *replacements if item == target }
49
+ self
50
+ end
51
+
38
52
  def to_sentence delimiter: ", ", conjunction: "and"
39
53
  case length
40
54
  when (3..) then "#{self[..-2].join delimiter}#{delimiter}#{conjunction} #{last}"
data/refinements.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "refinements"
5
- spec.version = "9.6.0"
5
+ spec.version = "9.7.1"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://www.alchemists.io/projects/refinements"
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: refinements
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.6.0
4
+ version: 9.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -28,7 +28,7 @@ cert_chain:
28
28
  CxDe2+VuChj4I1nvIHdu+E6XoEVlanUPKmSg6nddhkKn2gC45Kyzh6FZqnzH/CRp
29
29
  RFE=
30
30
  -----END CERTIFICATE-----
31
- date: 2022-07-17 00:00:00.000000000 Z
31
+ date: 2022-10-22 00:00:00.000000000 Z
32
32
  dependencies: []
33
33
  description:
34
34
  email:
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  requirements: []
86
- rubygems_version: 3.3.18
86
+ rubygems_version: 3.3.24
87
87
  signing_key:
88
88
  specification_version: 4
89
89
  summary: A collection of refinements to core Ruby objects.
metadata.gz.sig CHANGED
Binary file