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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.adoc +25 -1
- 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: 0dbec0b903b2ce6a78545bf34285ab60d20fd1b511975c750829a883107de915
|
4
|
+
data.tar.gz: 14c0fa259be4dd70fcc3766bcf745b9c267af3b1a58c0f32fc0f1fdfbb9d6458
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
1373
|
+
git clone https://github.com/bkuhlmann/refinements
|
1350
1374
|
cd refinements
|
1351
1375
|
bin/setup
|
1352
1376
|
----
|
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.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-
|
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.
|
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
|