supplement 2.22 → 2.24

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 (5) hide show
  1. checksums.yaml +4 -4
  2. data/README +2 -1
  3. data/lib/supplement.c +52 -0
  4. data/lib/supplement.h +2 -0
  5. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cfe383724f7aaa07dc2be7524d3ab6e11908ede513e133251b01989572343e59
4
- data.tar.gz: 64121897e3f8388666664d0911b74ae18a4b8c378b6c38737edc0414e5262629
3
+ metadata.gz: 196a040bf5dba1ea9778b2a9c2335698e6d43214832a3106bb6efbb616d718ac
4
+ data.tar.gz: 41af129cdd0a520ee715b9663395c63e39754a8be3a494bb62d8e7a4d30cf8c0
5
5
  SHA512:
6
- metadata.gz: '0549d67c614aad498ad70160933d2122290b864013ff73b564a57b8f80a8cceaa86c9c57dd222641be738dbf6232e0dccb78b9b3610888055fdf5706bf678f8a'
7
- data.tar.gz: eac0f15c6799f7e096abea90146351d33c905e85d78fe0e293a83a1ce611f96b10ba5bf6bc84c3f8271ac1822a8b702794066abe9c8210a5b3dddb0a88c94849
6
+ metadata.gz: fbf458038e5b477e340faf16ecbfa98058be9d2b3014253ce448666af627573c6b51eb9d4949fb0cf04af48b7bc42c15b304d39fa4ce3c2ceb0c0ac727a952b1
7
+ data.tar.gz: decd0d8dfa69fae98b8f03c4e19b06f9f28bf341d24bf38b83837ff8f955ec81a0b01904bd0c7bdee4077d7ec27c6c0f168997f861251f2c1aba0aca794aba50
data/README CHANGED
@@ -1,4 +1,4 @@
1
- = supplement 2.22 -- Useful Ruby enhancements
1
+ = supplement 2.24 -- Useful Ruby enhancements
2
2
 
3
3
 
4
4
  Some simple Ruby extensions.
@@ -55,6 +55,7 @@ Now here it is where I can just point to.
55
55
  * String#start_with?
56
56
  * String#end_with?
57
57
  * Array#notempty?
58
+ * Array#first=/last=
58
59
  * Hash#notempty?
59
60
  * Struct.[]
60
61
  * Integer.roman
data/lib/supplement.c CHANGED
@@ -814,6 +814,56 @@ rb_ary_notempty_p( VALUE ary)
814
814
  return RARRAY_LEN( ary) == 0 ? Qnil : ary;
815
815
  }
816
816
 
817
+ /*
818
+ * call-seq:
819
+ * first = obj -> obj
820
+ *
821
+ * Replace the first element. Equivalent to <code>ary[0]=</code>.
822
+ *
823
+ * a = [ -1, 39, 56]
824
+ * a.first = 42
825
+ * a #=> [42, 39, 56]
826
+ * a.unshift 266
827
+ * a.first /= 14
828
+ * a #=> [19, 42, 39, 56]
829
+ */
830
+
831
+ VALUE
832
+ rb_ary_first_set( VALUE ary, VALUE val)
833
+ {
834
+ 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");
838
+ RARRAY_ASET( ary, 0, val);
839
+ return val;
840
+ }
841
+
842
+ /*
843
+ * call-seq:
844
+ * last = obj -> obj
845
+ *
846
+ * Replace the last element. Equivalent to <code>ary[-1]=</code>.
847
+ *
848
+ * a = [ 42, 39, -1]
849
+ * a.last = 42
850
+ * a #=> [42, 39, 42]
851
+ * a.push 266
852
+ * a.last /= 14
853
+ * a #=> [42, 39, 42, 19]
854
+ */
855
+
856
+ VALUE
857
+ rb_ary_last_set( VALUE ary, VALUE val)
858
+ {
859
+ 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);
864
+ return val;
865
+ }
866
+
817
867
 
818
868
  /*
819
869
  * call-seq:
@@ -1449,6 +1499,8 @@ void Init_supplement( void)
1449
1499
  rb_define_method( rb_cNumeric, "cbrt", rb_num_cbrt, 0);
1450
1500
 
1451
1501
  rb_define_method( rb_cArray, "notempty?", rb_ary_notempty_p, 0);
1502
+ rb_define_method( rb_cArray, "first=", rb_ary_first_set, 1);
1503
+ rb_define_method( rb_cArray, "last=", rb_ary_last_set, 1);
1452
1504
  rb_define_method( rb_cArray, "indexes", rb_ary_indexes, 0);
1453
1505
  rb_define_alias( rb_cArray, "keys", "indexes");
1454
1506
  rb_define_method( rb_cArray, "range", rb_ary_range, 0);
data/lib/supplement.h CHANGED
@@ -50,6 +50,8 @@ extern VALUE rb_num_sqrt( VALUE);
50
50
  extern VALUE rb_num_cbrt( VALUE);
51
51
 
52
52
  extern VALUE rb_ary_notempty_p( VALUE);
53
+ extern VALUE rb_ary_first_set( VALUE, VALUE);
54
+ extern VALUE rb_ary_last_set( VALUE, VALUE);
53
55
  extern VALUE rb_ary_indexes( VALUE);
54
56
  extern VALUE rb_ary_range( VALUE);
55
57
  extern VALUE rb_ary_pick( int, VALUE *, VALUE);
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.22'
4
+ version: '2.24'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bertram Scharpf
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-04 00:00:00.000000000 Z
10
+ date: 2025-03-10 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rake
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  version: '0'
92
92
  requirements:
93
93
  - Ruby and the autorake gem
94
- rubygems_version: 3.6.2
94
+ rubygems_version: 3.6.4
95
95
  specification_version: 4
96
96
  summary: Simple Ruby extensions
97
97
  test_files: []