supplement 2.23 → 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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README +1 -1
  3. data/lib/supplement.c +19 -5
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3d7ee6d3e8eb25677cac8471ba79cbf665610dcb9b061b0e79e1ae138b64157
4
- data.tar.gz: 5f3753613e05e2878fa31aa81b8bb007e0fe399db578f1ece73ae76744abfba6
3
+ metadata.gz: 87253970f8149f1f091b4419997728d0317f6d847f95842a21dab6faf352ce75
4
+ data.tar.gz: 730dbbbb7d53ac21435f34f9639be86245b3b62c806df69902a3548cd7492c8a
5
5
  SHA512:
6
- metadata.gz: 28b038bda87536826cab7e3a9451ab73696e8958b687ef25b90a2c3b3a260464f58fecf1e39d9944b60aaa61c12363d3885ef12fe917ee611648418e8a102033
7
- data.tar.gz: b91a88ae34b04323ff296bc0c4fa303f729b053f0eb726ecd1d4fabc7c3d59c05dbda042567bfe3e0449d368dbaec80d676f8aaacd2b64b9b471a290a8158ddf
6
+ metadata.gz: deafd239c000947882607c24b2088ecd82e55d2033477646fefa7ecedaa4f0f844813a894dc9ef3846b3c4c30eca74043972c47ba7d61a414a4e0dfd0e33ddd0
7
+ data.tar.gz: a0cb32771d5ad142b05c645896fd05e68148e34ffd05d04d3bbac1f1db27bead3c39af3b0a65dd929a353e0e09643c7996a0e94c0818a88a5a1949ac78cfeac4
data/README CHANGED
@@ -1,4 +1,4 @@
1
- = supplement 2.23 -- Useful Ruby enhancements
1
+ = supplement 2.25 -- Useful Ruby enhancements
2
2
 
3
3
 
4
4
  Some simple Ruby extensions.
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);
@@ -831,16 +832,28 @@ rb_ary_notempty_p( VALUE ary)
831
832
  VALUE
832
833
  rb_ary_first_set( VALUE ary, VALUE val)
833
834
  {
834
- rb_ary_modify(ary);
835
- RARRAY_ASET(ary, 0, val);
835
+ rb_ary_modify( ary);
836
+ supplement_ary_assure_notempty( ary);
837
+ RARRAY_ASET( ary, 0, val);
836
838
  return val;
837
839
  }
838
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
+
839
851
  /*
840
852
  * call-seq:
841
853
  * last = obj -> obj
842
854
  *
843
- * Replace the last element. Equivalent to <code>ary[-1]=</code>.
855
+ * Replace the last element. Almost equivalent to
856
+ * <code>ary[-1]=</code> (works also for empty arrays).
844
857
  *
845
858
  * a = [ 42, 39, -1]
846
859
  * a.last = 42
@@ -853,8 +866,9 @@ rb_ary_first_set( VALUE ary, VALUE val)
853
866
  VALUE
854
867
  rb_ary_last_set( VALUE ary, VALUE val)
855
868
  {
856
- rb_ary_modify(ary);
857
- RARRAY_ASET(ary, RARRAY_LEN(ary)-1, val);
869
+ rb_ary_modify( ary);
870
+ supplement_ary_assure_notempty( ary);
871
+ RARRAY_ASET( ary, RARRAY_LEN( ary) - 1, val);
858
872
  return val;
859
873
  }
860
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.23'
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 00:00:00.000000000 Z
10
+ date: 2025-03-13 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rake