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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README +1 -1
  3. data/lib/supplement.c +16 -8
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 196a040bf5dba1ea9778b2a9c2335698e6d43214832a3106bb6efbb616d718ac
4
- data.tar.gz: 41af129cdd0a520ee715b9663395c63e39754a8be3a494bb62d8e7a4d30cf8c0
3
+ metadata.gz: 87253970f8149f1f091b4419997728d0317f6d847f95842a21dab6faf352ce75
4
+ data.tar.gz: 730dbbbb7d53ac21435f34f9639be86245b3b62c806df69902a3548cd7492c8a
5
5
  SHA512:
6
- metadata.gz: fbf458038e5b477e340faf16ecbfa98058be9d2b3014253ce448666af627573c6b51eb9d4949fb0cf04af48b7bc42c15b304d39fa4ce3c2ceb0c0ac727a952b1
7
- data.tar.gz: decd0d8dfa69fae98b8f03c4e19b06f9f28bf341d24bf38b83837ff8f955ec81a0b01904bd0c7bdee4077d7ec27c6c0f168997f861251f2c1aba0aca794aba50
6
+ metadata.gz: deafd239c000947882607c24b2088ecd82e55d2033477646fefa7ecedaa4f0f844813a894dc9ef3846b3c4c30eca74043972c47ba7d61a414a4e0dfd0e33ddd0
7
+ data.tar.gz: a0cb32771d5ad142b05c645896fd05e68148e34ffd05d04d3bbac1f1db27bead3c39af3b0a65dd929a353e0e09643c7996a0e94c0818a88a5a1949ac78cfeac4
data/README CHANGED
@@ -1,4 +1,4 @@
1
- = supplement 2.24 -- 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);
@@ -832,18 +833,27 @@ VALUE
832
833
  rb_ary_first_set( VALUE ary, VALUE val)
833
834
  {
834
835
  rb_ary_modify( ary);
835
- long len = RARRAY_LEN( ary);
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. Equivalent to <code>ary[-1]=</code>.
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
- long len = RARRAY_LEN( ary);
861
- if (len == 0)
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.24'
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