refinements 9.6.0 → 9.7.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5c0144180dd3a5cabe861b385cd0c766eaf54280ca6812dc6e82db4e564ce6c0
4
- data.tar.gz: b339710c168c98fffbe5b1994031f033041c9f6c16b0df96555cb80fd5cd7269
3
+ metadata.gz: bfcbba638db46745a2a7bed58489bea5a2942fb8d414d6803696ee78d12b8ae2
4
+ data.tar.gz: bf5d97f24387a1b46c90b2ebce6e20a66a8ef7f817b60f7029c58ef7d8897236
5
5
  SHA512:
6
- metadata.gz: 926090205f29ac111494e00e7de37b59b8549c6f979c8a0d62d852e9d87193093073ac0f005564243fc472eacf4de68f62bea8b1d45f3f363e113805758f726d
7
- data.tar.gz: 22a524d073a48922d6347119f01f4c059bbd2bba8f65a2e6573951b137b772dc3f7797a3596ccb850bb63159a9b2ab501bb334f7ac8a80f66ca93f55886bdb09
6
+ metadata.gz: 72fc04e99a5e2cc9f6d7adbc2b7c9d461f6d3246249eb1615379d2f64f871f5066c27bdedc95bda42cd44e247e4c793514f6885e11a497ce70980763bb00cb32
7
+ data.tar.gz: 16be117393cd04565ca945c1812e25d63169f7cb5400f4fa11bfe1aac27cbe3061deeeac6fb0e160c2538cf1f274cd1998e7e296f7c9e6e3cde39a0c5a822307
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.
@@ -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.0"
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.0
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-09-01 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.21
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