supplement 2.25 → 2.28

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87253970f8149f1f091b4419997728d0317f6d847f95842a21dab6faf352ce75
4
- data.tar.gz: 730dbbbb7d53ac21435f34f9639be86245b3b62c806df69902a3548cd7492c8a
3
+ metadata.gz: f85d589269b733a85677e23b294181ffe0c589b85b4a4d635d4071cfb11f9dee
4
+ data.tar.gz: 629cb0a6f688289737682b4483ce56b2d48ebc59329427e526b8422cc8dbb7f0
5
5
  SHA512:
6
- metadata.gz: deafd239c000947882607c24b2088ecd82e55d2033477646fefa7ecedaa4f0f844813a894dc9ef3846b3c4c30eca74043972c47ba7d61a414a4e0dfd0e33ddd0
7
- data.tar.gz: a0cb32771d5ad142b05c645896fd05e68148e34ffd05d04d3bbac1f1db27bead3c39af3b0a65dd929a353e0e09643c7996a0e94c0818a88a5a1949ac78cfeac4
6
+ metadata.gz: 35b071bcdc5240496f66ab0e288c3be3f9d22166f5fe817f01cd69ba64e19af7fc78c9a76fe10fc78d85addb8703861b87b9082c903a21a45c22e63033a6e8a5
7
+ data.tar.gz: 8d2d97d762991063639a8fd33d2d84ab876542e71b005c11744f74dfc3ab30d2412490b1dc9e9f699ce4334f0579ce10bdb4ad0f9fcacaa860c9ffcf67cbc119
data/LICENSE CHANGED
@@ -1,20 +1,24 @@
1
- = supplement Ruby Gem
1
+ # BSD-2-clause license, extended by language use conditions
2
2
 
3
-
4
- Copyright (C) 2009-2024, Bertram Scharpf <software@bertram-scharpf.de>.
3
+ Copyright (C) 2009-2025, Bertram Scharpf <software@bertram-scharpf.de>.
5
4
  All rights reserved.
6
5
 
7
6
  Redistribution and use in source and binary forms, with or without
8
7
  modification, are permitted provided that the following conditions are
9
8
  met:
10
9
 
11
- * Redistributions of source code must retain the above copyright
12
- notice, this list of conditions and the following disclaimer.
10
+ * Redistributions of source code must retain the above copyright
11
+ notice, this list of conditions and the following disclaimer.
12
+
13
+ * Redistributions in binary form must reproduce the above copyright
14
+ notice, this list of conditions and the following disclaimer in
15
+ the documentation and/or other materials provided with the
16
+ distribution.
13
17
 
14
- * Redistributions in binary form must reproduce the above copyright
15
- notice, this list of conditions and the following disclaimer in
16
- the documentation and/or other materials provided with the
17
- distribution.
18
+ * Redistributions must not contain any clauses about anticipated
19
+ harassment or discrimination, nor must they be held in a so-called
20
+ "inclusive language". As far as German language is used, the
21
+ conditions mentioned below additionally apply.
18
22
 
19
23
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20
24
  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -28,3 +32,21 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28
32
  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29
33
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
34
 
35
+
36
+ ## Use of the German Language
37
+
38
+ Beim Gebrauch deutscher Sprache sind Weiterentwicklungen und
39
+ -verbreitungen nur gestattet unter Einhaltung sowie abermaligen
40
+ Einforderns folgender zusätzlicher Bedingungen:
41
+
42
+ * Keine Verwendung von sogenannter „geschlechtergerechter Sprache“,
43
+ also Anfügen von weiblichen Endungen mit Binnen-I, Sternchen,
44
+ Doppelpunkt, Unterstrich oder ähnlichem, oder Konstruktionen, die
45
+ den Sachverhalt falsch wiedergeben („Radfahrende“, „Studierende“).
46
+
47
+ * Keine Verwendung der „reformierten Rechtschreibung“ von 1996,
48
+ insbesondere Doppel-S am Silbenende, „plazieren“ mit T, sowie
49
+ Großschreibung von Wendungen wie „des weiteren“.
50
+
51
+
52
+ <!-- vim:set ft=markdown : -->
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # supplement 2.28 -- Useful Ruby enhancements
2
+
3
+ Some simple Ruby extensions.
4
+
5
+
6
+ ## Motivation
7
+
8
+ The original motivation was my conviction that a language that has a
9
+ `Numeric#nonzero?` method induces a programming style that as well demands
10
+ for a `String#notempty?` method.
11
+
12
+
13
+ ## Description
14
+
15
+ These are methods on standard classes that didn't manage to become part of
16
+ the Ruby interpreter. (Although, some did in the meantime.)
17
+
18
+ They are all very small, most of them have less than 15 lines of code.
19
+ So they would not be a weight in the Ruby interpreter but it is very
20
+ difficult to convince a majority that they belong there.
21
+
22
+ The methods won't be useful for everybody but some programmers may like
23
+ to make them part of their programming style.
24
+
25
+ If you like to get taunted, then go to the Ruby mailing list and propose
26
+ one of them to be included into the Ruby standard.
27
+
28
+
29
+ ## Contents (uncomplete)
30
+
31
+ * `String#notempty?`
32
+ * `String#head`
33
+ * `String#tail`
34
+ * `String#rest`
35
+ * `String#starts_with?`/`ends_with?`
36
+ * `Array#notempty?`
37
+ * `Array#first=`/`last=`
38
+ * `Hash#notempty?`
39
+ * `Struct.[]`
40
+ * `Integer.roman`
41
+ * `Date.easter`
42
+ * `TCPServer/UNIXServer.accept` with a code block
43
+ * `File system stats`
44
+ * `Process.renice`
45
+ * Interval timer
46
+ * `LockedFile`
47
+
48
+
49
+ ## Copyright
50
+
51
+ * (C) 2009-2025 Bertram Scharpf <software@bertram-scharpf.de>
52
+ * License: [BSD-2-Clause+](./LICENSE)
53
+ * Repository: [ruby-supplement](https://github.com/BertramScharpf/ruby-supplement)
54
+
data/lib/mkrf_conf CHANGED
@@ -11,13 +11,6 @@ Autorake.configure {
11
11
  extending_ruby
12
12
 
13
13
  if RUBY_VERSION < "3.3" then
14
- if RUBY_VERSION < "2.7" then
15
- if RUBY_VERSION < "2.6" then
16
- enable :dir_children
17
- end
18
- else
19
- enable :super_kwargs
20
- end
21
14
  enable :old_io_functions
22
15
  end
23
16
 
@@ -26,9 +19,6 @@ Autorake.configure {
26
19
  have_header "ruby/io.h"
27
20
  have_header "ruby/re.h"
28
21
 
29
- have_function "rb_thread_wait_for"
30
-
31
- have_function "cbrt"
32
-
22
+ have_header "sys/vfs.h"
33
23
  }
34
24
 
@@ -5,19 +5,28 @@
5
5
  #include "filesys.h"
6
6
 
7
7
  #include <stdlib.h>
8
- #ifdef __FSID_T_TYPE
8
+ #ifdef HAVE_HEADER_SYS_VFS_H
9
9
  /* Linux */
10
10
  #include <sys/vfs.h>
11
+ #define FSID_val __val
11
12
  #else
12
13
  #include <sys/param.h>
13
14
  #include <sys/mount.h>
15
+ #define FSID_val val
14
16
  #endif
15
17
 
16
18
 
17
19
 
18
20
  static struct statfs *get_statfs( VALUE);
19
21
 
20
- static ID id_mul;
22
+ static ID id_mul = 0;
23
+
24
+ static const rb_data_type_t fsstat_data_type = {
25
+ "supplement:statfs",
26
+ { NULL, &ruby_xfree, NULL, NULL},
27
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
28
+ };
29
+
21
30
 
22
31
  /*
23
32
  * Document-class: Filesys
@@ -41,7 +50,8 @@ static ID id_mul;
41
50
  VALUE
42
51
  rb_fsstat_s_alloc( VALUE klass)
43
52
  {
44
- return Data_Wrap_Struct( klass, NULL, &free, (struct statfs *) NULL);
53
+ struct statfs *s;
54
+ return TypedData_Make_Struct( klass, struct statfs, &fsstat_data_type, s);
45
55
  }
46
56
 
47
57
  /*
@@ -55,56 +65,22 @@ rb_fsstat_s_alloc( VALUE klass)
55
65
  VALUE
56
66
  rb_fsstat_init( VALUE obj, VALUE dname)
57
67
  {
58
- struct statfs st, *nst;
68
+ struct statfs *st;
59
69
 
60
- SafeStringValue( dname);
70
+ TypedData_Get_Struct( obj, struct statfs, &fsstat_data_type, st);
61
71
 
62
- if (statfs( StringValueCStr( dname), &st) == -1)
72
+ SafeStringValue( dname);
73
+ if (statfs( StringValueCStr( dname), st) == -1)
63
74
  rb_sys_fail( RSTRING_PTR(dname));
64
- if (DATA_PTR(obj)) {
65
- free( DATA_PTR(obj));
66
- DATA_PTR(obj) = NULL;
67
- }
68
- nst = ALLOC(struct statfs);
69
- *nst = st;
70
- DATA_PTR(obj) = nst;
71
-
72
75
  return Qnil;
73
76
  }
74
77
 
75
- /* :nodoc: */
76
- VALUE
77
- rb_fsstat_init_copy( VALUE copy, VALUE orig)
78
- {
79
- struct statfs *nst;
80
-
81
- if (copy == orig)
82
- return orig;
83
-
84
- rb_check_frozen( copy);
85
- if (!rb_obj_is_instance_of( orig, rb_obj_class( copy)))
86
- rb_raise(rb_eTypeError, "wrong argument class");
87
- if (DATA_PTR(copy)) {
88
- free( DATA_PTR(copy));
89
- DATA_PTR(copy) = NULL;
90
- }
91
- if (DATA_PTR(orig)) {
92
- nst = ALLOC(struct statfs);
93
- *nst = *(struct statfs *) DATA_PTR(orig);
94
- DATA_PTR(copy) = nst;
95
- }
96
-
97
- return copy;
98
- }
99
78
 
100
- /* :nodoc: */
101
79
  struct statfs *
102
80
  get_statfs( VALUE self)
103
81
  {
104
82
  struct statfs *st;
105
- Data_Get_Struct(self, struct statfs, st);
106
- if (!st)
107
- rb_raise( rb_eTypeError, "uninitialized Filesys::Stat");
83
+ TypedData_Get_Struct( self, struct statfs, &fsstat_data_type, st);
108
84
  return st;
109
85
  }
110
86
 
@@ -209,13 +185,6 @@ rb_fsstat_ffree( VALUE self)
209
185
  * Filesystem id; array of 2 integers.
210
186
  */
211
187
 
212
- #ifdef __FSID_T_TYPE
213
- /* Linux */
214
- #define FSID_val __val
215
- #else
216
- #define FSID_val val
217
- #endif
218
-
219
188
  VALUE
220
189
  rb_fsstat_fsid( VALUE self)
221
190
  {
@@ -365,12 +334,11 @@ void Init_filesys( void)
365
334
  VALUE rb_cFilesys;
366
335
  VALUE rb_cFilesysStat;
367
336
 
368
- rb_cFilesys = rb_define_class( "Filesys", rb_cObject);
337
+ rb_cFilesys = rb_define_module( "Filesys");
369
338
 
370
339
  rb_cFilesysStat = rb_define_class_under( rb_cFilesys, "Stat", rb_cObject);
371
- rb_define_alloc_func( rb_cFilesysStat, rb_fsstat_s_alloc);
340
+ rb_define_alloc_func( rb_cFilesysStat, rb_fsstat_s_alloc);
372
341
  rb_define_method( rb_cFilesysStat, "initialize", rb_fsstat_init, 1);
373
- rb_define_method( rb_cFilesysStat, "initialize_copy", rb_fsstat_init_copy, 1);
374
342
 
375
343
  rb_define_method( rb_cFilesysStat, "type", rb_fsstat_type , 0);
376
344
  rb_define_method( rb_cFilesysStat, "bsize", rb_fsstat_bsize , 0);
@@ -31,20 +31,14 @@ rb_locked_init( int argc, VALUE *argv, VALUE self)
31
31
  #ifdef FEATURE_OLD_IO_FUNCTIONS
32
32
  rb_io_t *fptr;
33
33
  #endif
34
- #ifdef HAVE_FUNC_RB_THREAD_WAIT_FOR
35
34
  struct timeval time;
36
- #endif
37
35
  int op;
38
36
 
39
37
  #ifdef FEATURE_OLD_IO_FUNCTIONS
40
38
  GetOpenFile( self, fptr);
41
39
  #endif
42
40
 
43
- #ifdef FEATURE_SUPER_KWARGS
44
41
  rb_call_super_kw(argc, argv, RB_PASS_CALLED_KEYWORDS);
45
- #else
46
- rb_call_super( argc, argv);
47
- #endif
48
42
 
49
43
  #ifdef FEATURE_OLD_IO_FUNCTIONS
50
44
  op = fptr->mode & FMODE_WRITABLE ? LOCK_EX : LOCK_SH;
@@ -72,13 +66,9 @@ rb_locked_init( int argc, VALUE *argv, VALUE self)
72
66
  if (rb_respond_to( self, id_lock_failed))
73
67
  rb_funcall( self, id_lock_failed, 0);
74
68
  else {
75
- #ifdef HAVE_FUNC_RB_THREAD_WAIT_FOR
76
69
  time.tv_sec = 0;
77
70
  time.tv_usec = 100 * 1000;
78
71
  rb_thread_wait_for(time);
79
- #else
80
- rb_thread_polling();
81
- #endif
82
72
  }
83
73
  break;
84
74
  default:
@@ -5,8 +5,8 @@
5
5
  #include <ruby/io.h>
6
6
 
7
7
 
8
- static ID id_accept_orig;
9
- static ID id_close;
8
+ static ID id_accept_orig = 0;
9
+ static ID id_close = 0;
10
10
 
11
11
  static VALUE socket_close( VALUE);
12
12
 
data/lib/supplement.c CHANGED
@@ -10,34 +10,20 @@
10
10
  #include <ruby/io.h>
11
11
  #include <ruby/re.h>
12
12
 
13
- #ifdef FEATURE_THREAD_EXCLUSIVE
14
- #ifdef HAVE_HEADER_RUBYSIG_H
15
- #include <rubysig.h>
16
- #endif
17
- #endif
18
-
19
13
 
20
14
  static void supplement_ary_assure_notempty( VALUE);
21
15
  static VALUE supplement_index_blk( VALUE);
22
16
  static VALUE supplement_index_ref( VALUE, VALUE);
23
17
  static VALUE supplement_rindex_blk( VALUE);
24
18
  static VALUE supplement_rindex_ref( VALUE, VALUE);
25
- #ifdef FEATURE_ARRAY_INDEX_WITH_BLOCK
26
- static VALUE supplement_index_val( VALUE, VALUE);
27
- static VALUE supplement_rindex_val( VALUE, VALUE);
28
- #endif
29
19
  static VALUE supplement_do_unumask( VALUE);
30
- #ifdef FEATURE_THREAD_EXCLUSIVE
31
- static VALUE bsruby_set_thread_critical( VALUE);
32
- #endif
33
-
34
20
 
35
21
 
36
- static ID id_delete_at;
37
- static ID id_cmp;
38
- static ID id_eqq;
39
- static ID id_mkdir;
40
- static ID id_index;
22
+ static ID id_delete_at = 0;
23
+ static ID id_cmp = 0;
24
+ static ID id_eqq = 0;
25
+ static ID id_mkdir = 0;
26
+ static ID id_index = 0;
41
27
 
42
28
 
43
29
 
@@ -102,31 +88,6 @@ rb_obj_nil_if( VALUE obj, VALUE val)
102
88
  * Document-module: Kernel
103
89
  */
104
90
 
105
- #ifdef FEATURE_KERNEL_TAP
106
-
107
- /*
108
- * call-seq:
109
- * tap { |x| ... } -> obj
110
- *
111
- * Yields <code>x</code> to the block, and then returns <code>x</code>.
112
- * The primary purpose of this method is to "tap into" a method chain,
113
- * in order to perform operations on intermediate results within the chain.
114
- *
115
- * (1..10) .tap { |x| puts "original: #{x.inspect}" }
116
- * .to_a .tap { |x| puts "array: #{x.inspect}" }
117
- * .select { |x| x%2==0 } .tap { |x| puts "evens: #{x.inspect}" }
118
- * .map { |x| x*x } .tap { |x| puts "squares: #{x.inspect}" }
119
- *
120
- */
121
-
122
- VALUE
123
- rb_krn_tap( VALUE obj)
124
- {
125
- rb_yield( obj);
126
- return obj;
127
- }
128
-
129
- #endif
130
91
 
131
92
  /*
132
93
  * call-seq:
@@ -362,30 +323,6 @@ rb_str_cut_bang( VALUE str, VALUE len)
362
323
  }
363
324
 
364
325
 
365
- #ifdef FEATURE_STRING_CLEAR
366
-
367
- /*
368
- * call-seq:
369
- * clear -> self
370
- *
371
- * Set to empty string. Equivalent to <code>str.replace ""</code>.
372
- *
373
- * a = "hello" #=> "hello"
374
- * a.clear #=> ""
375
- * a.empty? #=> true
376
- */
377
-
378
- VALUE
379
- rb_str_clear( VALUE str)
380
- {
381
- rb_str_modify( str);
382
- rb_str_resize( str, 0);
383
- return str;
384
- }
385
-
386
- #endif
387
-
388
-
389
326
  /*
390
327
  * call-seq:
391
328
  * head( n = 1) -> str
@@ -454,41 +391,6 @@ rb_str_tail( int argc, VALUE *argv, VALUE str)
454
391
  }
455
392
 
456
393
 
457
- #ifdef FEATURE_STRING_START_WITH
458
-
459
- /*
460
- * call-seq:
461
- * start_with?( oth) -> true or false
462
- *
463
- * Checks whether the head is <code>oth</code>.
464
- *
465
- * "sys-apps".start_with?( "sys-") #=> true
466
- */
467
-
468
- VALUE
469
- rb_str_start_with_p( VALUE str, VALUE oth)
470
- {
471
- return NIL_P( rb_str_starts_with_p( str, oth)) ? Qfalse : Qtrue;
472
- }
473
-
474
-
475
- /*
476
- * call-seq:
477
- * end_with?( oth) -> true or false
478
- *
479
- * Checks whether the tail is <code>oth</code>.
480
- *
481
- * "sys-apps".end_with?( "-apps") #=> true
482
- */
483
-
484
- VALUE
485
- rb_str_end_with_p( VALUE str, VALUE oth)
486
- {
487
- return NIL_P( rb_str_ends_with_p( str, oth)) ? Qfalse : Qtrue;
488
- }
489
-
490
- #endif
491
-
492
394
  /*
493
395
  * call-seq:
494
396
  * starts_with?( oth) -> nil or int
@@ -499,7 +401,8 @@ rb_str_end_with_p( VALUE str, VALUE oth)
499
401
  * "sys-apps".starts_with?( "sys-") #=> 4
500
402
  *
501
403
  * Caution! The Ruby 1.9.3 method #start_with? (notice the missing s)
502
- * just returns +true+ or +false+.
404
+ * just returns +true+ or +false+. Mnemonics: "s" = prepare for
405
+ * <code>#slice</code>.
503
406
  */
504
407
 
505
408
  VALUE
@@ -555,25 +458,6 @@ rb_str_ends_with_p( VALUE str, VALUE oth)
555
458
  return INT2FIX( rb_str_strlen( str) - rb_str_strlen( ost));
556
459
  }
557
460
 
558
- #ifdef FEATURE_STRING_ORD
559
-
560
- /*
561
- * call-seq:
562
- * ord() -> nil or int
563
- *
564
- * Returns the ASCII value of the first character, if any.
565
- *
566
- * Caution! For UTF-8 characters, this will return the first byte's value.
567
- * This will do no harm in Ruby 1.8 but the standard Ruby 1.9 +String#ord+
568
- * returns the first codepoint. Please do not overwrite that method.
569
- */
570
-
571
- VALUE rb_str_ord( VALUE str)
572
- {
573
- return RSTRING_LEN( str) > 0 ? INT2FIX( RSTRING_PTR( str)[ 0]) : Qnil;
574
- }
575
-
576
- #endif
577
461
 
578
462
  /*
579
463
  * call-seq:
@@ -622,78 +506,6 @@ rb_str_axe( int argc, VALUE *argv, VALUE str)
622
506
  * Document-class: Numeric
623
507
  */
624
508
 
625
- /*
626
- * call-seq:
627
- * pos? -> true or false
628
- *
629
- * Check whether +num+ is positive.
630
- *
631
- */
632
-
633
- VALUE
634
- rb_num_pos_p( VALUE num)
635
- {
636
- VALUE r = Qfalse;
637
-
638
- switch (TYPE( num)) {
639
- case T_FIXNUM:
640
- if (NUM2LONG( num) > 0)
641
- r = Qtrue;
642
- break;
643
-
644
- case T_BIGNUM:
645
- if (RBIGNUM_SIGN( num)) /* 0 is not a Bignum. */
646
- r = Qtrue;
647
- break;
648
-
649
- case T_FLOAT:
650
- if (RFLOAT_VALUE( num) > 0.0)
651
- r = Qtrue;
652
- break;
653
-
654
- default:
655
- return rb_num_neg_p( rb_funcall( INT2FIX( 0), id_cmp, 1, num));
656
- break;
657
- }
658
- return r;
659
- }
660
-
661
- /*
662
- * call-seq:
663
- * neg? -> true or false
664
- *
665
- * Check whether +num+ is negative.
666
- *
667
- */
668
-
669
- VALUE
670
- rb_num_neg_p( VALUE num)
671
- {
672
- VALUE r = Qfalse;
673
-
674
- switch (TYPE( num)) {
675
- case T_FIXNUM:
676
- if (NUM2LONG( num) < 0)
677
- r = Qtrue;
678
- break;
679
-
680
- case T_BIGNUM:
681
- if (!RBIGNUM_SIGN( num)) /* 0 is not a Bignum. */
682
- r = Qtrue;
683
- break;
684
-
685
- case T_FLOAT:
686
- if (RFLOAT_VALUE( num) < 0.0)
687
- r = Qtrue;
688
- break;
689
-
690
- default:
691
- return rb_num_neg_p( rb_funcall( num, id_cmp, 1, INT2FIX( 0)));
692
- break;
693
- }
694
- return r;
695
- }
696
-
697
509
  /*
698
510
  * call-seq:
699
511
  * grammatical sing, plu -> str
@@ -755,42 +567,24 @@ rb_num_sqrt( VALUE num)
755
567
  return rb_float_new( sqrt( RFLOAT_VALUE( rb_Float( num))));
756
568
  }
757
569
 
570
+ /*
571
+ * Document-class: Rational
572
+ */
573
+
758
574
  /*
759
575
  * call-seq:
760
- * num.cbrt -> num
576
+ * rat.inv -> rat
761
577
  *
762
- * Cube root.
578
+ * The reciprocal.
763
579
  *
764
- * 27.cbrt #=> 3.0
580
+ * 5/7r.inv #=> 7/5r
765
581
  */
766
582
 
767
583
  VALUE
768
- rb_num_cbrt( VALUE num)
584
+ rb_rat_inverse( VALUE rat)
769
585
  {
770
- #if HAVE_FUNC_CBRT
771
- return rb_float_new( cbrt( RFLOAT_VALUE( rb_Float( num))));
772
- #else
773
- double n;
774
- int neg;
775
- int i;
776
-
777
- n = RFLOAT_VALUE( rb_Float( num));
778
- if ((neg = n < 0))
779
- n = -n;
780
- n = sqrt( sqrt( n));
781
- i = 2;
782
- for (;;) {
783
- double w = n;
784
- int j;
785
-
786
- for (j=i;j;--j) w = sqrt( w);
787
- i *= 2;
788
- w *= n;
789
- if (n == w) break;
790
- n = w;
791
- }
792
- return rb_float_new( neg ? -n : n);
793
- #endif
586
+ /* There is an internal function `rb_ration_reciprocal()`, but that cannot be reached from here. */
587
+ return rb_Rational( rb_rational_den( rat), rb_rational_num( rat));
794
588
  }
795
589
 
796
590
 
@@ -1034,96 +828,6 @@ supplement_rindex_blk( VALUE ary)
1034
828
  }
1035
829
 
1036
830
 
1037
- #ifdef FEATURE_ARRAY_INDEX_WITH_BLOCK
1038
-
1039
- /*
1040
- * call-seq:
1041
- * index( obj) -> int or nil
1042
- * index() { |elem| ... } -> int or nil
1043
- *
1044
- * Returns the index of the first object in <code>self</code> such that
1045
- * is <code>==</code> to <code>obj</code> or the <em>block</em> returns
1046
- * <code>true</code>. If no match is found, <code>nil</code> is
1047
- * returned.
1048
- *
1049
- * a = %w(a b c d e)
1050
- * a.index("b") #=> 1
1051
- * a.index("z") #=> nil
1052
- * a.index { |e| e >= "b" } #=> 1
1053
- * a.index { |e| e >= "q" } #=> nil
1054
- */
1055
-
1056
- VALUE
1057
- rb_ary_index( int argc, VALUE *argv, VALUE ary)
1058
- {
1059
- VALUE val;
1060
-
1061
- if (rb_scan_args( argc, argv, "01", &val) == 1) {
1062
- if (rb_block_given_p())
1063
- rb_warning( "given block not used");
1064
- return supplement_index_val( ary, val);
1065
- } else
1066
- return supplement_index_blk( ary);
1067
- return Qnil;
1068
- }
1069
-
1070
- VALUE
1071
- supplement_index_val( VALUE ary, VALUE val)
1072
- {
1073
- long i;
1074
-
1075
- for (i = 0; i < RARRAY_LEN( ary); i++)
1076
- if (rb_equal( RARRAY_PTR( ary)[ i], val))
1077
- return LONG2NUM( i);
1078
- return Qnil;
1079
- }
1080
-
1081
-
1082
- /*
1083
- * call-seq:
1084
- * rindex( obj) -> int or nil
1085
- * rindex() { |elem| ... } -> int or nil
1086
- *
1087
- * Returns the index of the first object in <code>self</code> such that
1088
- * is <code>==</code> to <code>obj</code> or the <em>block</em> returns
1089
- * <code>true</code>. If no match is found, <code>nil</code> is
1090
- * returned. Search from right to left.
1091
- *
1092
- * a = %w(a b c d e)
1093
- * a.rindex("b") #=> 1
1094
- * a.rindex("z") #=> nil
1095
- * a.rindex { |e| e >= "b" } #=> 4
1096
- * a.rindex { |e| e >= "q" } #=> nil
1097
- */
1098
-
1099
- VALUE
1100
- rb_ary_rindex( int argc, VALUE *argv, VALUE ary)
1101
- {
1102
- VALUE val;
1103
-
1104
- if (rb_scan_args( argc, argv, "01", &val) == 1) {
1105
- if (rb_block_given_p())
1106
- rb_warning( "given block not used");
1107
- return supplement_rindex_val( ary, val);
1108
- } else
1109
- return supplement_rindex_blk( ary);
1110
- return Qnil;
1111
- }
1112
-
1113
- VALUE
1114
- supplement_rindex_val( VALUE ary, VALUE val)
1115
- {
1116
- long i;
1117
-
1118
- for (i = RARRAY_LEN( ary); i;)
1119
- if (rb_equal( RARRAY_PTR( ary)[ --i], val))
1120
- return LONG2NUM( i);
1121
- return Qnil;
1122
- }
1123
-
1124
- #endif
1125
-
1126
-
1127
831
  /*
1128
832
  * Document-class: Hash
1129
833
  */
@@ -1258,31 +962,6 @@ rb_dir_s_mkdir_bang( int argc, VALUE *argv, VALUE dir)
1258
962
  }
1259
963
 
1260
964
 
1261
- #ifdef FEATURE_DIR_CHILDREN
1262
-
1263
- /*
1264
- * call-seq:
1265
- * children() -> ary
1266
- *
1267
- * Entries without <code>"."</code> and <code>".."</code>.
1268
- *
1269
- */
1270
-
1271
- VALUE
1272
- rb_dir_children( VALUE self)
1273
- {
1274
- VALUE e;
1275
-
1276
- e = rb_funcall( self, rb_intern( "entries"), 0);
1277
- rb_ary_delete( e, rb_str_new( ".", 1));
1278
- rb_ary_delete( e, rb_str_new( "..", 2));
1279
- return e;
1280
- }
1281
-
1282
- #endif
1283
-
1284
-
1285
-
1286
965
  /*
1287
966
  * Document-class: Match
1288
967
  */
@@ -1382,40 +1061,6 @@ rb_struct_fields( int argc, VALUE *argv, VALUE strct)
1382
1061
  }
1383
1062
 
1384
1063
 
1385
- #ifdef FEATURE_THREAD_EXCLUSIVE
1386
-
1387
- /*
1388
- * Document-class: Thread
1389
- */
1390
-
1391
- /*
1392
- * call-seq:
1393
- * Thread.exclusive { ... } -> obj
1394
- *
1395
- * Sets the global ``thread critical'' condition temporarily. Return
1396
- * value is the object returned by the <em>block</em>.
1397
- */
1398
-
1399
- VALUE
1400
- rb_thread_exclusive( void)
1401
- {
1402
- VALUE old_tc = rb_thread_critical;
1403
-
1404
- rb_thread_critical = Qtrue;
1405
- return rb_ensure( rb_yield, Qnil, bsruby_set_thread_critical, old_tc);
1406
- }
1407
-
1408
- VALUE
1409
- bsruby_set_thread_critical( VALUE c)
1410
- {
1411
- rb_thread_critical = c;
1412
- return Qnil;
1413
- }
1414
-
1415
- #endif
1416
-
1417
-
1418
-
1419
1064
  /*
1420
1065
  * Document-class: Struct
1421
1066
  */
@@ -1435,7 +1080,6 @@ bsruby_set_thread_critical( VALUE c)
1435
1080
  */
1436
1081
 
1437
1082
 
1438
-
1439
1083
  /*
1440
1084
  * Document-class: Object
1441
1085
  */
@@ -1465,9 +1109,6 @@ void Init_supplement( void)
1465
1109
  {
1466
1110
  rb_define_method( rb_cObject, "new_string", rb_obj_new_string, 0);
1467
1111
  rb_define_method( rb_cObject, "nil_if", rb_obj_nil_if, 1);
1468
- #ifdef FEATURE_KERNEL_TAP
1469
- rb_define_method( rb_mKernel, "tap", rb_krn_tap, 0);
1470
- #endif
1471
1112
  rb_define_method( rb_mKernel, "tap!", rb_krn_tap_bang, 0);
1472
1113
  rb_define_method( rb_mKernel, "with", rb_krn_with, 0);
1473
1114
 
@@ -1481,30 +1122,17 @@ void Init_supplement( void)
1481
1122
  rb_define_method( rb_cString, "notempty?", rb_str_notempty_p, 0);
1482
1123
  rb_define_method( rb_cString, "eat", rb_str_eat, -1);
1483
1124
  rb_define_method( rb_cString, "cut!", rb_str_cut_bang, 1);
1484
- #ifdef FEATURE_STRING_CLEAR
1485
- rb_define_method( rb_cString, "clear", rb_str_clear, 0);
1486
- #endif
1487
1125
  rb_define_method( rb_cString, "head", rb_str_head, -1);
1488
1126
  rb_define_method( rb_cString, "rest", rb_str_rest, -1);
1489
1127
  rb_define_method( rb_cString, "tail", rb_str_tail, -1);
1490
- #ifdef FEATURE_STRING_START_WITH
1491
- rb_define_method( rb_cString, "start_with?", rb_str_start_with_p, 1);
1492
- rb_define_method( rb_cString, "end_with?", rb_str_end_with_p, 1);
1493
- #endif
1494
1128
  rb_define_method( rb_cString, "starts_with?", rb_str_starts_with_p, 1);
1495
1129
  rb_define_method( rb_cString, "ends_with?", rb_str_ends_with_p, 1);
1496
- rb_define_alias( rb_cString, "starts_with", "start_with?");
1497
- rb_define_alias( rb_cString, "ends_with", "end_with?");
1498
- #ifdef FEATURE_STRING_ORD
1499
- rb_define_method( rb_cString, "ord", rb_str_ord, 0);
1500
- #endif
1501
1130
  rb_define_method( rb_cString, "axe", rb_str_axe, -1);
1502
1131
 
1503
- rb_define_method( rb_cNumeric, "pos?", rb_num_pos_p, 0);
1504
- rb_define_method( rb_cNumeric, "neg?", rb_num_neg_p, 0);
1505
1132
  rb_define_method( rb_cNumeric, "grammatical", rb_num_grammatical, 2);
1506
1133
  rb_define_method( rb_cNumeric, "sqrt", rb_num_sqrt, 0);
1507
- rb_define_method( rb_cNumeric, "cbrt", rb_num_cbrt, 0);
1134
+
1135
+ rb_define_method( rb_cRational, "inv", rb_rat_inverse, 0);
1508
1136
 
1509
1137
  rb_define_method( rb_cArray, "notempty?", rb_ary_notempty_p, 0);
1510
1138
  rb_define_method( rb_cArray, "first=", rb_ary_first_set, 1);
@@ -1514,10 +1142,6 @@ void Init_supplement( void)
1514
1142
  rb_define_method( rb_cArray, "range", rb_ary_range, 0);
1515
1143
  rb_define_method( rb_cArray, "pick", rb_ary_pick, -1);
1516
1144
  rb_define_method( rb_cArray, "rpick", rb_ary_rpick, -1);
1517
- #ifdef FEATURE_ARRAY_INDEX_WITH_BLOCK
1518
- rb_define_method( rb_cArray, "index", rb_ary_index, -1);
1519
- rb_define_method( rb_cArray, "rindex", rb_ary_rindex, -1);
1520
- #endif
1521
1145
 
1522
1146
  rb_define_method( rb_cHash, "notempty?", rb_hash_notempty_p, 0);
1523
1147
 
@@ -1525,19 +1149,11 @@ void Init_supplement( void)
1525
1149
 
1526
1150
  rb_define_singleton_method( rb_cDir, "current", rb_dir_s_current, 0);
1527
1151
  rb_define_singleton_method( rb_cDir, "mkdir!", rb_dir_s_mkdir_bang, -1);
1528
- #ifdef FEATURE_DIR_CHILDREN
1529
- rb_define_method( rb_cDir, "children", rb_dir_children, 0);
1530
- #endif
1531
1152
  rb_define_alias( rb_cDir, "entries!", "children");
1532
1153
 
1533
1154
  rb_define_method( rb_cMatch, "begin", rb_match_begin, -1);
1534
1155
  rb_define_method( rb_cMatch, "end", rb_match_end, -1);
1535
1156
 
1536
- #ifdef FEATURE_THREAD_EXCLUSIVE
1537
- rb_define_singleton_method( rb_cThread, "exclusive",
1538
- rb_thread_exclusive, 0);
1539
- #endif
1540
-
1541
1157
  rb_define_alias( rb_singleton_class( rb_cStruct), "[]", "new");
1542
1158
  rb_define_method( rb_cStruct, "fields", rb_struct_fields, -1);
1543
1159
  rb_define_alias( rb_cStruct, "fetch_values", "fields");
data/lib/supplement.h CHANGED
@@ -11,9 +11,6 @@
11
11
 
12
12
  extern VALUE rb_obj_new_string( VALUE);
13
13
  extern VALUE rb_obj_nil_if( VALUE, VALUE);
14
- #ifdef FEATURE_KERNEL_TAP
15
- extern VALUE rb_krn_tap( VALUE);
16
- #endif
17
14
  extern VALUE rb_krn_tap_bang( VALUE);
18
15
  extern VALUE rb_krn_with( VALUE);
19
16
 
@@ -26,28 +23,16 @@ extern VALUE rb_str_new_string( VALUE);
26
23
  extern VALUE rb_str_notempty_p( VALUE);
27
24
  extern VALUE rb_str_eat( int, VALUE *, VALUE);
28
25
  extern VALUE rb_str_cut_bang( VALUE, VALUE);
29
- #ifdef FEATURE_STRING_CLEAR
30
- extern VALUE rb_str_clear( VALUE);
31
- #endif
32
26
  extern VALUE rb_str_head( int, VALUE *, VALUE);
33
27
  extern VALUE rb_str_rest( int, VALUE *, VALUE);
34
28
  extern VALUE rb_str_tail( int, VALUE *, VALUE);
35
- #ifdef FEATURE_STRING_START_WITH
36
- extern VALUE rb_str_start_with_p( VALUE, VALUE);
37
- extern VALUE rb_str_end_with_p( VALUE, VALUE);
38
- #endif
39
29
  extern VALUE rb_str_starts_with_p( VALUE, VALUE);
40
30
  extern VALUE rb_str_ends_with_p( VALUE, VALUE);
41
- #ifdef FEATURE_STRING_ORD
42
- extern VALUE rb_str_ord( VALUE);
43
- #endif
44
31
  extern VALUE rb_str_axe( int, VALUE *, VALUE);
45
32
 
46
- extern VALUE rb_num_pos_p( VALUE);
47
- extern VALUE rb_num_neg_p( VALUE);
48
33
  extern VALUE rb_num_grammatical( VALUE, VALUE, VALUE);
49
34
  extern VALUE rb_num_sqrt( VALUE);
50
- extern VALUE rb_num_cbrt( VALUE);
35
+ extern VALUE rb_rat_inverse( VALUE);
51
36
 
52
37
  extern VALUE rb_ary_notempty_p( VALUE);
53
38
  extern VALUE rb_ary_first_set( VALUE, VALUE);
@@ -56,25 +41,16 @@ extern VALUE rb_ary_indexes( VALUE);
56
41
  extern VALUE rb_ary_range( VALUE);
57
42
  extern VALUE rb_ary_pick( int, VALUE *, VALUE);
58
43
  extern VALUE rb_ary_rpick( int, VALUE *, VALUE);
59
- #ifdef FEATURE_ARRAY_INDEX_WITH_BLOCK
60
- extern VALUE rb_ary_index( int, VALUE *, VALUE);
61
- extern VALUE rb_ary_rindex( int, VALUE *, VALUE);
62
- #endif
63
44
 
64
45
  extern VALUE rb_hash_notempty_p( VALUE);
65
46
 
66
47
  extern VALUE rb_file_s_umask( int, VALUE *, VALUE);
67
48
  extern VALUE rb_dir_s_current( VALUE);
68
49
  extern VALUE rb_dir_s_mkdir_bang( int, VALUE *, VALUE);
69
- extern VALUE rb_dir_children( VALUE);
70
50
 
71
51
  extern VALUE rb_match_begin( int, VALUE *, VALUE);
72
52
  extern VALUE rb_match_end( int, VALUE *, VALUE);
73
53
 
74
- #ifdef FEATURE_THREAD_EXCLUSIVE
75
- extern VALUE rb_thread_exclusive( void);
76
- #endif
77
-
78
54
  extern VALUE rb_struct_fields( int, VALUE *, VALUE);
79
55
 
80
56
  extern VALUE rb_nil_to_bool( 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.25'
4
+ version: '2.28'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bertram Scharpf
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-13 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rake
@@ -45,11 +45,11 @@ executables: []
45
45
  extensions:
46
46
  - lib/mkrf_conf
47
47
  extra_rdoc_files:
48
- - README
49
48
  - LICENSE
49
+ - README.md
50
50
  files:
51
51
  - LICENSE
52
- - README
52
+ - README.md
53
53
  - examples/teatimer
54
54
  - lib/Rakefile
55
55
  - lib/mkrf_conf
@@ -74,16 +74,14 @@ homepage: https://github.com/BertramScharpf/ruby-supplement
74
74
  licenses:
75
75
  - BSD-2-Clause
76
76
  metadata: {}
77
- rdoc_options:
78
- - "--main"
79
- - README
77
+ rdoc_options: []
80
78
  require_paths:
81
79
  - lib
82
80
  required_ruby_version: !ruby/object:Gem::Requirement
83
81
  requirements:
84
82
  - - ">="
85
83
  - !ruby/object:Gem::Version
86
- version: 2.0.0
84
+ version: 3.1.0
87
85
  required_rubygems_version: !ruby/object:Gem::Requirement
88
86
  requirements:
89
87
  - - ">="
@@ -91,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
89
  version: '0'
92
90
  requirements:
93
91
  - Ruby and the autorake gem
94
- rubygems_version: 3.6.4
92
+ rubygems_version: 3.7.1
95
93
  specification_version: 4
96
94
  summary: Simple Ruby extensions
97
95
  test_files: []
data/README DELETED
@@ -1,68 +0,0 @@
1
- = supplement 2.25 -- Useful Ruby enhancements
2
-
3
-
4
- Some simple Ruby extensions.
5
-
6
-
7
- == Author
8
-
9
- Bertram Scharpf <software@bertram-scharpf.de>
10
-
11
-
12
- == Motivation
13
-
14
- The original motivation was my conviction that a language that has a
15
- Numeric#nonzero? method induces a programming style that as well demands
16
- for a String#notempty? method.
17
-
18
-
19
-
20
- == Description
21
-
22
- These are methods on standard classes that didn't manage to become part of
23
- the Ruby interpreter. (Although, some did in the meantime.)
24
-
25
- They are all very small, most of them have less than 15 lines of code.
26
- So they would not be a weight in the Ruby interpreter but it is very
27
- difficult to convince a majority that they belong there.
28
-
29
- The methods won't be useful for everybody but some programmers may like
30
- to make them part of their programming style.
31
-
32
- If you like to get taunted, then go to the Ruby mailing list and propose
33
- one of them to be included into the Ruby standard.
34
-
35
-
36
-
37
- == Intention
38
-
39
- In my own code I use quite often a method <code>String#notempty?</code>
40
- that does almost the same as <code>Numeric#nonzero?</code>. Every
41
- attempt proposing it for the Ruby standard implementation has failed;
42
- the discussion evolves the same every time.
43
-
44
- Now here it is where I can just point to.
45
-
46
-
47
-
48
- == Contents (uncomplete)
49
-
50
- * String#notempty?
51
- * String#clear
52
- * String#head
53
- * String#tail
54
- * String#rest
55
- * String#start_with?
56
- * String#end_with?
57
- * Array#notempty?
58
- * Array#first=/last=
59
- * Hash#notempty?
60
- * Struct.[]
61
- * Integer.roman
62
- * Date.easter
63
- * TCPServer/UNIXServer.accept with a code block
64
- * File system stats
65
- * Process.renice
66
- * Interval timer
67
- * LockedFile
68
-