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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.adoc +24 -0
- data/lib/refinements/arrays.rb +14 -0
- data/refinements.gemspec +1 -1
- data.tar.gz.sig +0 -0
- metadata +3 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfcbba638db46745a2a7bed58489bea5a2942fb8d414d6803696ee78d12b8ae2
|
4
|
+
data.tar.gz: bf5d97f24387a1b46c90b2ebce6e20a66a8ef7f817b60f7029c58ef7d8897236
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
data/lib/refinements/arrays.rb
CHANGED
@@ -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
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.
|
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-
|
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.
|
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
|