supplement 2.24 → 2.25
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
- data/README +1 -1
- data/lib/supplement.c +16 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87253970f8149f1f091b4419997728d0317f6d847f95842a21dab6faf352ce75
|
4
|
+
data.tar.gz: 730dbbbb7d53ac21435f34f9639be86245b3b62c806df69902a3548cd7492c8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: deafd239c000947882607c24b2088ecd82e55d2033477646fefa7ecedaa4f0f844813a894dc9ef3846b3c4c30eca74043972c47ba7d61a414a4e0dfd0e33ddd0
|
7
|
+
data.tar.gz: a0cb32771d5ad142b05c645896fd05e68148e34ffd05d04d3bbac1f1db27bead3c39af3b0a65dd929a353e0e09643c7996a0e94c0818a88a5a1949ac78cfeac4
|
data/README
CHANGED
data/lib/supplement.c
CHANGED
@@ -17,6 +17,7 @@
|
|
17
17
|
#endif
|
18
18
|
|
19
19
|
|
20
|
+
static void supplement_ary_assure_notempty( VALUE);
|
20
21
|
static VALUE supplement_index_blk( VALUE);
|
21
22
|
static VALUE supplement_index_ref( VALUE, VALUE);
|
22
23
|
static VALUE supplement_rindex_blk( VALUE);
|
@@ -832,18 +833,27 @@ VALUE
|
|
832
833
|
rb_ary_first_set( VALUE ary, VALUE val)
|
833
834
|
{
|
834
835
|
rb_ary_modify( ary);
|
835
|
-
|
836
|
-
if (len == 0)
|
837
|
-
rb_raise( rb_eArgError, "cannot replace first element of an empty array");
|
836
|
+
supplement_ary_assure_notempty( ary);
|
838
837
|
RARRAY_ASET( ary, 0, val);
|
839
838
|
return val;
|
840
839
|
}
|
841
840
|
|
841
|
+
void
|
842
|
+
supplement_ary_assure_notempty( VALUE ary)
|
843
|
+
{
|
844
|
+
long len = RARRAY_LEN( ary);
|
845
|
+
if (len == 0) {
|
846
|
+
VALUE q = Qnil;
|
847
|
+
rb_ary_cat( ary, &q, 1);
|
848
|
+
}
|
849
|
+
}
|
850
|
+
|
842
851
|
/*
|
843
852
|
* call-seq:
|
844
853
|
* last = obj -> obj
|
845
854
|
*
|
846
|
-
* Replace the last element.
|
855
|
+
* Replace the last element. Almost equivalent to
|
856
|
+
* <code>ary[-1]=</code> (works also for empty arrays).
|
847
857
|
*
|
848
858
|
* a = [ 42, 39, -1]
|
849
859
|
* a.last = 42
|
@@ -857,10 +867,8 @@ VALUE
|
|
857
867
|
rb_ary_last_set( VALUE ary, VALUE val)
|
858
868
|
{
|
859
869
|
rb_ary_modify( ary);
|
860
|
-
|
861
|
-
|
862
|
-
rb_raise( rb_eArgError, "cannot replace last element of an empty array");
|
863
|
-
RARRAY_ASET( ary, len - 1, val);
|
870
|
+
supplement_ary_assure_notempty( ary);
|
871
|
+
RARRAY_ASET( ary, RARRAY_LEN( ary) - 1, val);
|
864
872
|
return val;
|
865
873
|
}
|
866
874
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: supplement
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '2.
|
4
|
+
version: '2.25'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bertram Scharpf
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-03-
|
10
|
+
date: 2025-03-13 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: rake
|