supplement 2.28 → 2.30

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.md +1 -1
  3. data/lib/supplement.c +130 -66
  4. data/lib/supplement.h +4 -2
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f85d589269b733a85677e23b294181ffe0c589b85b4a4d635d4071cfb11f9dee
4
- data.tar.gz: 629cb0a6f688289737682b4483ce56b2d48ebc59329427e526b8422cc8dbb7f0
3
+ metadata.gz: fd387c214f1666040ad8c1d4844543310d0616449c08cf3b69a3f11cdc83e93a
4
+ data.tar.gz: 1b5460d3ecf411e6c7cda40510a8649f8ecd9a42ea405d1284f4b3d57148fa9d
5
5
  SHA512:
6
- metadata.gz: 35b071bcdc5240496f66ab0e288c3be3f9d22166f5fe817f01cd69ba64e19af7fc78c9a76fe10fc78d85addb8703861b87b9082c903a21a45c22e63033a6e8a5
7
- data.tar.gz: 8d2d97d762991063639a8fd33d2d84ab876542e71b005c11744f74dfc3ab30d2412490b1dc9e9f699ce4334f0579ce10bdb4ad0f9fcacaa860c9ffcf67cbc119
6
+ metadata.gz: 513e9ff98266e00ef2ee11f47961cadb834074a7c7d889708032c14515aaf2db28d95a593d25d6904a66d29f030b4cb9e65219152ae88b6cca9b9a532a60c260
7
+ data.tar.gz: c8c0be3cff0f29e4d5476f694d78f44105222b58f8e86ac37977567a6b702efe65bc0b9f2d5a0dbf4288761b348231cea62fe6ce90f00c964dcd73fff2d9180a
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # supplement 2.28 -- Useful Ruby enhancements
1
+ # supplement 2.30 -- Useful Ruby enhancements
2
2
 
3
3
  Some simple Ruby extensions.
4
4
 
data/lib/supplement.c CHANGED
@@ -111,8 +111,10 @@ rb_krn_tap_bang( VALUE obj)
111
111
  * call-seq:
112
112
  * with { |x| ... } -> obj
113
113
  *
114
+ * Warning. This method will be removed. Use +Kernel#then+ instead.
115
+ *
114
116
  * Yields +x+ to the block.
115
- * This difference to +tap+ is that the block's result will be returned.
117
+ * The difference to +tap+ is that the block's result will be returned.
116
118
  *
117
119
  * Use this to narrow your namespace.
118
120
  *
@@ -121,6 +123,8 @@ rb_krn_tap_bang( VALUE obj)
121
123
  VALUE
122
124
  rb_krn_with( VALUE obj)
123
125
  {
126
+ rb_category_warning(RB_WARN_CATEGORY_DEPRECATED,
127
+ "Kernel#with will be removed from the supplement gem. Use Kernel#then instead.");
124
128
  return rb_yield( obj);
125
129
  }
126
130
 
@@ -393,112 +397,167 @@ rb_str_tail( int argc, VALUE *argv, VALUE str)
393
397
 
394
398
  /*
395
399
  * call-seq:
396
- * starts_with?( oth) -> nil or int
400
+ * axe( n = 80) -> str
397
401
  *
398
- * Checks whether the head is <code>oth</code>. Returns length of
399
- * <code>oth</code> when matching.
402
+ * Cut off everthing beyond then <code>n</code>th character. Replace the
403
+ * last bytes by ellipses.
404
+ *
405
+ * a = "Redistribution and use in source and binary forms, with or without"
406
+ * a.axe( 16) #=> "Redistributio..."
407
+ */
408
+
409
+ VALUE
410
+ rb_str_axe( int argc, VALUE *argv, VALUE str)
411
+ {
412
+ VALUE n;
413
+ VALUE ret;
414
+ long newlen, oldlen;
415
+
416
+ if (rb_scan_args( argc, argv, "01", &n) == 1 && !NIL_P( n))
417
+ newlen = NUM2LONG( n);
418
+ else
419
+ newlen = 80;
420
+ if (newlen < 0)
421
+ return Qnil;
422
+
423
+ oldlen = rb_str_strlen( str);
424
+ if (newlen < oldlen) {
425
+ VALUE ell;
426
+ long e;
427
+
428
+ ell = rb_str_new2( "...");
429
+ e = rb_str_strlen( ell);
430
+ if (newlen > e) {
431
+ ret = rb_str_substr( str, 0, newlen - e);
432
+ rb_str_append( ret, ell);
433
+ } else
434
+ ret = rb_str_substr( str, 0, newlen);
435
+ } else
436
+ ret = str;
437
+ return ret;
438
+ }
439
+
440
+
441
+ /*
442
+ * call-seq:
443
+ * starts_with?( *oth) -> nil or int
444
+ *
445
+ * Checks whether the head is one of <code>oth</code>. Returns the position
446
+ * where the match ends.
400
447
  *
401
448
  * "sys-apps".starts_with?( "sys-") #=> 4
402
449
  *
403
- * Caution! The Ruby 1.9.3 method #start_with? (notice the missing s)
450
+ * Caution! The Ruby 1.9.3 method #start_with? (note the missing s)
404
451
  * just returns +true+ or +false+. Mnemonics: "s" = prepare for
405
452
  * <code>#slice</code>.
406
453
  */
407
454
 
408
455
  VALUE
409
- rb_str_starts_with_p( VALUE str, VALUE oth)
456
+ rb_str_starts_with_p( int argc, VALUE *argv, VALUE str)
410
457
  {
411
- long i;
412
- char *s, *o;
413
- VALUE ost;
458
+ int j;
414
459
 
415
- ost = rb_string_value( &oth);
416
- i = RSTRING_LEN( ost);
417
- if (i > RSTRING_LEN( str))
418
- return Qnil;
419
- s = RSTRING_PTR( str);
420
- o = RSTRING_PTR( ost);
421
- for (; i; i--, s++, o++) {
422
- if (*s != *o)
460
+ for (j = 0; j < argc; j++) {
461
+ long i;
462
+ char *s, *o;
463
+ VALUE ost;
464
+ VALUE oth = argv[ j];
465
+
466
+ ost = rb_string_value( &oth);
467
+ i = RSTRING_LEN( ost);
468
+ if (i > RSTRING_LEN( str))
423
469
  return Qnil;
470
+ s = RSTRING_PTR( str);
471
+ o = RSTRING_PTR( ost);
472
+ for (; i; i--, s++, o++) {
473
+ if (*s != *o)
474
+ break;
475
+ }
476
+ if (!i)
477
+ return INT2FIX( rb_str_strlen( ost));
424
478
  }
425
- return INT2FIX( rb_str_strlen( ost));
479
+ return Qnil;
426
480
  }
427
481
 
428
482
 
429
483
  /*
430
484
  * call-seq:
431
- * ends_with?( oth) -> nil or int
485
+ * ends_with?( *oth) -> nil or int
432
486
  *
433
- * Checks whether the tail is <code>oth</code>. Returns the position
434
- * where <code>oth</code> starts when matching.
487
+ * Checks whether the tail is one of <code>oth</code>. Returns the position
488
+ * where the match starts.
435
489
  *
436
490
  * "sys-apps".ends_with?( "-apps") #=> 3
437
491
  *
438
- * Caution! The Ruby 1.9.3 method #start_with? (notice the missing s)
492
+ * Caution! The Ruby 1.9.3 method #start_with? (note the missing s)
439
493
  * just returns +true+ or +false+.
440
494
  */
441
495
 
442
496
  VALUE
443
- rb_str_ends_with_p( VALUE str, VALUE oth)
497
+ rb_str_ends_with_p( int argc, VALUE *argv, VALUE str)
444
498
  {
445
- long i;
446
- char *s, *o;
447
- VALUE ost;
499
+ int j;
448
500
 
449
- ost = rb_string_value( &oth);
450
- i = RSTRING_LEN( ost);
451
- if (i > RSTRING_LEN( str))
452
- return Qnil;
453
- s = RSTRING_END( str);
454
- o = RSTRING_END( ost);
455
- for (; i; i--)
456
- if (*--s != *--o)
501
+ for (j = 0; j < argc; j++) {
502
+ long i;
503
+ char *s, *o;
504
+ VALUE ost;
505
+ VALUE oth = argv[ j];
506
+
507
+ ost = rb_string_value( &oth);
508
+ i = RSTRING_LEN( ost);
509
+ if (i > RSTRING_LEN( str))
457
510
  return Qnil;
458
- return INT2FIX( rb_str_strlen( str) - rb_str_strlen( ost));
511
+ s = RSTRING_END( str);
512
+ o = RSTRING_END( ost);
513
+ for (; i; i--)
514
+ if (*--s != *--o)
515
+ break;
516
+ if (!i)
517
+ return INT2FIX( rb_str_strlen( str) - rb_str_strlen( ost));
518
+ }
519
+ return Qnil;
459
520
  }
460
521
 
461
522
 
462
523
  /*
463
524
  * call-seq:
464
- * axe( n = 80) -> str
525
+ * starts_with?( oth) -> nil or int
465
526
  *
466
- * Cut off everthing beyond then <code>n</code>th character. Replace the
467
- * last bytes by ellipses.
527
+ * Checks whether the head is <code>oth</code>. Returns length of
528
+ * <code>oth</code> when matching.
468
529
  *
469
- * a = "Redistribution and use in source and binary forms, with or without"
470
- * a.axe( 16) #=> "Redistributio..."
530
+ * :"sys-apps".starts_with?( "sys-") #=> 4
531
+ *
532
+ * Caution! The Ruby 1.9.3 method #start_with? (note the missing s)
533
+ * just returns +true+ or +false+. Mnemonics: "s" = prepare for
534
+ * <code>#slice</code>.
471
535
  */
472
536
 
473
537
  VALUE
474
- rb_str_axe( int argc, VALUE *argv, VALUE str)
538
+ rb_sym_starts_with_p( int argc, VALUE *argv, VALUE sym)
475
539
  {
476
- VALUE n;
477
- VALUE ret;
478
- long newlen, oldlen;
540
+ return rb_str_starts_with_p(argc, argv, rb_sym2str(sym));
541
+ }
479
542
 
480
- if (rb_scan_args( argc, argv, "01", &n) == 1 && !NIL_P( n))
481
- newlen = NUM2LONG( n);
482
- else
483
- newlen = 80;
484
- if (newlen < 0)
485
- return Qnil;
486
543
 
487
- oldlen = rb_str_strlen( str);
488
- if (newlen < oldlen) {
489
- VALUE ell;
490
- long e;
544
+ /*
545
+ * call-seq:
546
+ * ends_with?( oth) -> nil or int
547
+ *
548
+ * Checks whether the tail is <code>oth</code>. Returns the position
549
+ * where <code>oth</code> starts when matching.
550
+ *
551
+ * :"sys-apps".ends_with?( "-apps") #=> 3
552
+ *
553
+ * Caution! The Ruby 1.9.3 method #start_with? (note the missing s)
554
+ * just returns +true+ or +false+.
555
+ */
491
556
 
492
- ell = rb_str_new2( "...");
493
- e = rb_str_strlen( ell);
494
- if (newlen > e) {
495
- ret = rb_str_substr( str, 0, newlen - e);
496
- rb_str_append( ret, ell);
497
- } else
498
- ret = rb_str_substr( str, 0, newlen);
499
- } else
500
- ret = str;
501
- return ret;
557
+ VALUE
558
+ rb_sym_ends_with_p( int argc, VALUE *argv, VALUE sym)
559
+ {
560
+ return rb_str_ends_with_p(argc, argv, rb_sym2str(sym));
502
561
  }
503
562
 
504
563
 
@@ -1125,9 +1184,11 @@ void Init_supplement( void)
1125
1184
  rb_define_method( rb_cString, "head", rb_str_head, -1);
1126
1185
  rb_define_method( rb_cString, "rest", rb_str_rest, -1);
1127
1186
  rb_define_method( rb_cString, "tail", rb_str_tail, -1);
1128
- rb_define_method( rb_cString, "starts_with?", rb_str_starts_with_p, 1);
1129
- rb_define_method( rb_cString, "ends_with?", rb_str_ends_with_p, 1);
1130
1187
  rb_define_method( rb_cString, "axe", rb_str_axe, -1);
1188
+ rb_define_method( rb_cString, "starts_with?", rb_str_starts_with_p, -1);
1189
+ rb_define_method( rb_cString, "ends_with?", rb_str_ends_with_p, -1);
1190
+ rb_define_method( rb_cSymbol, "starts_with?", rb_sym_starts_with_p, -1);
1191
+ rb_define_method( rb_cSymbol, "ends_with?", rb_sym_ends_with_p, -1);
1131
1192
 
1132
1193
  rb_define_method( rb_cNumeric, "grammatical", rb_num_grammatical, 2);
1133
1194
  rb_define_method( rb_cNumeric, "sqrt", rb_num_sqrt, 0);
@@ -1145,12 +1206,15 @@ void Init_supplement( void)
1145
1206
 
1146
1207
  rb_define_method( rb_cHash, "notempty?", rb_hash_notempty_p, 0);
1147
1208
 
1209
+ rb_undef_method( rb_singleton_class( rb_cFile), "umask");
1148
1210
  rb_define_singleton_method( rb_cFile, "umask", rb_file_s_umask, -1);
1149
1211
 
1150
1212
  rb_define_singleton_method( rb_cDir, "current", rb_dir_s_current, 0);
1151
1213
  rb_define_singleton_method( rb_cDir, "mkdir!", rb_dir_s_mkdir_bang, -1);
1152
1214
  rb_define_alias( rb_cDir, "entries!", "children");
1153
1215
 
1216
+ rb_undef_method( rb_cMatch, "begin");
1217
+ rb_undef_method( rb_cMatch, "end");
1154
1218
  rb_define_method( rb_cMatch, "begin", rb_match_begin, -1);
1155
1219
  rb_define_method( rb_cMatch, "end", rb_match_end, -1);
1156
1220
 
data/lib/supplement.h CHANGED
@@ -26,9 +26,11 @@ extern VALUE rb_str_cut_bang( VALUE, VALUE);
26
26
  extern VALUE rb_str_head( int, VALUE *, VALUE);
27
27
  extern VALUE rb_str_rest( int, VALUE *, VALUE);
28
28
  extern VALUE rb_str_tail( int, VALUE *, VALUE);
29
- extern VALUE rb_str_starts_with_p( VALUE, VALUE);
30
- extern VALUE rb_str_ends_with_p( VALUE, VALUE);
31
29
  extern VALUE rb_str_axe( int, VALUE *, VALUE);
30
+ extern VALUE rb_str_starts_with_p( int argc, VALUE *argv, VALUE);
31
+ extern VALUE rb_str_ends_with_p( int argc, VALUE *argv, VALUE);
32
+ extern VALUE rb_sym_starts_with_p( int argc, VALUE *argv, VALUE);
33
+ extern VALUE rb_sym_ends_with_p( int argc, VALUE *argv, VALUE);
32
34
 
33
35
  extern VALUE rb_num_grammatical( VALUE, VALUE, VALUE);
34
36
  extern VALUE rb_num_sqrt( VALUE);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: supplement
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.28'
4
+ version: '2.30'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bertram Scharpf