supplement 2.33 → 2.34
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 +4 -4
- data/README.md +1 -1
- data/lib/supplement.c +195 -36
- data/lib/supplement.h +5 -0
- metadata +1 -2
- data/examples/teatimer +0 -87
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8b3c14cf8891cd883edf8ad0ba621aae216f01d3a935d221c89e31a25ec76f0d
|
|
4
|
+
data.tar.gz: 616736bd166c84a60ebd9ae0670863f6ba26f018f69c61caed5aff7f9d10496e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bd0005f7224a3b0fd28f9e7a8c69ea6ea30c698d49253e24d006adf1a20b480b60f74161a1f939b0460e88afe9e0e9c8cf5c1d9e0b1fd0d7dfb14e66f67764e2
|
|
7
|
+
data.tar.gz: 5e8d529b3c3a78d7dbf44c033f11027032a463ca19b046e985904c4b75525876c1e00a50a6ea94247ef40579d65cfd59e25342de1abaf06048dca84427f099ff
|
data/README.md
CHANGED
data/lib/supplement.c
CHANGED
|
@@ -11,22 +11,37 @@
|
|
|
11
11
|
#include <ruby/re.h>
|
|
12
12
|
|
|
13
13
|
|
|
14
|
+
#define SUPPLEMENT_VERSION "2.34"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
#define SPL_CSTR(s) rb_str_new( (s), sizeof (s) - 1)
|
|
19
|
+
|
|
20
|
+
|
|
14
21
|
static long supplement_args_len_default( int, VALUE *);
|
|
15
22
|
static void supplement_ary_assure_notempty( VALUE);
|
|
16
23
|
static VALUE supplement_index_blk( VALUE);
|
|
17
24
|
static VALUE supplement_index_ref( VALUE, VALUE);
|
|
18
25
|
static VALUE supplement_rindex_blk( VALUE);
|
|
19
26
|
static VALUE supplement_rindex_ref( VALUE, VALUE);
|
|
27
|
+
static long supplement_find_nth( VALUE, VALUE, VALUE (*)( VALUE, long, VALUE));
|
|
28
|
+
static VALUE supplement_find_nth_result( VALUE, long, VALUE);
|
|
29
|
+
static VALUE supplement_delete_nth_result( VALUE, long, VALUE);
|
|
30
|
+
|
|
20
31
|
static VALUE supplement_do_unumask( VALUE);
|
|
21
32
|
|
|
22
33
|
|
|
34
|
+
static const char *supplement_scope = "::";
|
|
23
35
|
static const char *supplement_ellipse = "...";
|
|
36
|
+
static const char *supplement_dot = ".";
|
|
24
37
|
|
|
25
38
|
static ID id_delete_at = 0;
|
|
26
|
-
static ID
|
|
27
|
-
static ID
|
|
28
|
-
static ID id_mkdir
|
|
29
|
-
static ID
|
|
39
|
+
static ID id_eqq = 0;
|
|
40
|
+
static ID id_cmp = 0;
|
|
41
|
+
static ID id_mkdir = 0;
|
|
42
|
+
static ID id_abs = 0;
|
|
43
|
+
static ID id_div = 0;
|
|
44
|
+
static ID id_zero_p = 0;
|
|
30
45
|
|
|
31
46
|
|
|
32
47
|
|
|
@@ -81,8 +96,6 @@ rb_obj_new_string( VALUE obj)
|
|
|
81
96
|
VALUE
|
|
82
97
|
rb_obj_nil_if( VALUE obj, VALUE val)
|
|
83
98
|
{
|
|
84
|
-
if (!id_eqq)
|
|
85
|
-
id_eqq = rb_intern( "===");
|
|
86
99
|
return RTEST( rb_funcall( val, id_eqq, 1, obj)) ? Qnil : obj;
|
|
87
100
|
}
|
|
88
101
|
|
|
@@ -128,7 +141,7 @@ rb_module_plain_name( VALUE cls)
|
|
|
128
141
|
VALUE i;
|
|
129
142
|
|
|
130
143
|
n = rb_str_dup( rb_funcall( cls, rb_intern( "name"), 0));
|
|
131
|
-
i = rb_funcall( n, rb_intern( "rindex"), 1,
|
|
144
|
+
i = rb_funcall( n, rb_intern( "rindex"), 1, SPL_CSTR( supplement_scope));
|
|
132
145
|
if (!NIL_P( i)) {
|
|
133
146
|
i = rb_funcall( i, rb_intern( "+"), 1, INT2FIX( 2));
|
|
134
147
|
rb_funcall( n, rb_intern( "slice!"), 2, INT2FIX( 0), i);
|
|
@@ -553,20 +566,9 @@ rb_str_ends_with_p( int argc, VALUE *argv, VALUE str)
|
|
|
553
566
|
|
|
554
567
|
|
|
555
568
|
/*
|
|
556
|
-
*
|
|
557
|
-
* notempy?( oth) -> nil or sym
|
|
558
|
-
*
|
|
559
|
-
* Checks whether the head is <code>oth</code>. Returns length of
|
|
560
|
-
* <code>oth</code> when matching.
|
|
561
|
-
*
|
|
562
|
-
* :"sys-apps".starts_with?( "sys-") #=> 4
|
|
563
|
-
*
|
|
564
|
-
* Caution! The Ruby 1.9.3 method #start_with? (note the missing s)
|
|
565
|
-
* just returns +true+ or +false+. Mnemonics: "s" = prepare for
|
|
566
|
-
* <code>#slice</code>.
|
|
569
|
+
* Document-class: Symbol
|
|
567
570
|
*/
|
|
568
571
|
|
|
569
|
-
|
|
570
572
|
/*
|
|
571
573
|
* call-seq:
|
|
572
574
|
* notempty? -> nil or self
|
|
@@ -578,8 +580,8 @@ rb_str_ends_with_p( int argc, VALUE *argv, VALUE str)
|
|
|
578
580
|
* :"".notempty? #=> nil
|
|
579
581
|
*
|
|
580
582
|
* This seems to be quite useless. Its only purpose is to avoid either type
|
|
581
|
-
* detection or error catching
|
|
582
|
-
* empty.
|
|
583
|
+
* detection or error catching when other objects are asked whether they're
|
|
584
|
+
* not empty.
|
|
583
585
|
*/
|
|
584
586
|
|
|
585
587
|
VALUE
|
|
@@ -668,6 +670,8 @@ rb_num_grammatical( VALUE num, VALUE sing, VALUE plu)
|
|
|
668
670
|
break;
|
|
669
671
|
|
|
670
672
|
default:
|
|
673
|
+
if (!id_cmp)
|
|
674
|
+
id_cmp = rb_intern( "<=>");
|
|
671
675
|
l = NUM2LONG( rb_funcall( num, id_cmp, 1, INT2FIX( 1)));
|
|
672
676
|
if (l == 0)
|
|
673
677
|
return sing;
|
|
@@ -695,6 +699,47 @@ rb_num_sqrt( VALUE num)
|
|
|
695
699
|
return rb_float_new( sqrt( RFLOAT_VALUE( rb_Float( num))));
|
|
696
700
|
}
|
|
697
701
|
|
|
702
|
+
|
|
703
|
+
/*
|
|
704
|
+
* Document-class: Integer
|
|
705
|
+
*/
|
|
706
|
+
|
|
707
|
+
/*
|
|
708
|
+
* call-seq:
|
|
709
|
+
* int.length( base = nil) -> int
|
|
710
|
+
*
|
|
711
|
+
* Length of mantissa. Default base is <code>10</code>.
|
|
712
|
+
*
|
|
713
|
+
* 1234.length #=> 4
|
|
714
|
+
*/
|
|
715
|
+
|
|
716
|
+
VALUE
|
|
717
|
+
rb_int_length( int argc, VALUE *argv, VALUE num)
|
|
718
|
+
{
|
|
719
|
+
VALUE base;
|
|
720
|
+
VALUE x;
|
|
721
|
+
long n;
|
|
722
|
+
|
|
723
|
+
if (!id_abs)
|
|
724
|
+
id_abs = rb_intern( "abs");
|
|
725
|
+
if (!id_div)
|
|
726
|
+
id_div = rb_intern( "div");
|
|
727
|
+
if (!id_zero_p)
|
|
728
|
+
id_zero_p = rb_intern( "zero?");
|
|
729
|
+
|
|
730
|
+
if (rb_scan_args( argc, argv, "01", &base) != 1)
|
|
731
|
+
base = Qnil;
|
|
732
|
+
if (NIL_P( base))
|
|
733
|
+
base = LONG2NUM( 10);
|
|
734
|
+
n = 0;
|
|
735
|
+
x = rb_funcall( num, id_abs, 0);
|
|
736
|
+
while (!RTEST(rb_funcall( x, id_zero_p, 0))) {
|
|
737
|
+
n++;
|
|
738
|
+
x = rb_funcall( x, id_div, 1, base);
|
|
739
|
+
}
|
|
740
|
+
return LONG2NUM( n);
|
|
741
|
+
}
|
|
742
|
+
|
|
698
743
|
/*
|
|
699
744
|
* Document-class: Rational
|
|
700
745
|
*/
|
|
@@ -842,8 +887,8 @@ rb_ary_indexes( VALUE ary)
|
|
|
842
887
|
* pick( ref) -> obj or nil
|
|
843
888
|
* pick { |elem| ... } -> obj or nil
|
|
844
889
|
*
|
|
845
|
-
* Deletes the element where first <code>ref === obj</code>
|
|
846
|
-
* <em>block</em> first returns
|
|
890
|
+
* Deletes the element where first <code>ref === obj</code> or the
|
|
891
|
+
* <em>block</em> first returns a true value. The result will be
|
|
847
892
|
* <code>nil</code> if nothing is found.
|
|
848
893
|
*
|
|
849
894
|
* a = %w(ant bat cat dog)
|
|
@@ -874,8 +919,6 @@ supplement_index_ref( VALUE ary, VALUE ref)
|
|
|
874
919
|
{
|
|
875
920
|
long i, j;
|
|
876
921
|
|
|
877
|
-
if (!id_eqq)
|
|
878
|
-
id_eqq = rb_intern( "===");
|
|
879
922
|
for (i = 0, j = RARRAY_LEN( ary); j > 0; i++, j--) {
|
|
880
923
|
if (RTEST( rb_funcall( ref, id_eqq, 1, RARRAY_PTR( ary)[ i])))
|
|
881
924
|
return LONG2NUM( i);
|
|
@@ -900,8 +943,8 @@ supplement_index_blk( VALUE ary)
|
|
|
900
943
|
* rpick( ref) -> obj or nil
|
|
901
944
|
* rpick { |elem| ... } -> obj or nil
|
|
902
945
|
*
|
|
903
|
-
* Deletes the element where first <code>ref === obj</code>
|
|
904
|
-
* <em>block</em> first returns
|
|
946
|
+
* Deletes the element where first <code>ref === obj</code> or the
|
|
947
|
+
* <em>block</em> first returns a true value. The result will be
|
|
905
948
|
* <code>nil</code> if nothing is found. Search from right to left.
|
|
906
949
|
*
|
|
907
950
|
* a = %w(ant cow bat cat dog)
|
|
@@ -932,8 +975,6 @@ supplement_rindex_ref( VALUE ary, VALUE ref)
|
|
|
932
975
|
{
|
|
933
976
|
long i;
|
|
934
977
|
|
|
935
|
-
if (!id_eqq)
|
|
936
|
-
id_eqq = rb_intern( "===");
|
|
937
978
|
for (i = RARRAY_LEN( ary); i;) {
|
|
938
979
|
--i;
|
|
939
980
|
if (RTEST( rb_funcall( ref, id_eqq, 1, RARRAY_PTR( ary)[ i])))
|
|
@@ -956,6 +997,119 @@ supplement_rindex_blk( VALUE ary)
|
|
|
956
997
|
}
|
|
957
998
|
|
|
958
999
|
|
|
1000
|
+
/*
|
|
1001
|
+
* call-seq:
|
|
1002
|
+
* lstrip! { |elem| ... } -> nil or self
|
|
1003
|
+
*
|
|
1004
|
+
* Strip all elements from left where the block returns a true value.
|
|
1005
|
+
* Returns <code>nil</code> when the array is empty afterwards.
|
|
1006
|
+
*
|
|
1007
|
+
* a = %w(ant bat cow dog eel fox gnu)
|
|
1008
|
+
* a.lstrip! { |e| e =~ /a/ } #=> [ "cow", "dog", "eel", "fox", "gnu"]
|
|
1009
|
+
* a.lstrip! { |e| e.length == 3 } #=> nil
|
|
1010
|
+
*/
|
|
1011
|
+
|
|
1012
|
+
VALUE
|
|
1013
|
+
rb_ary_lstrip_bang( VALUE ary)
|
|
1014
|
+
{
|
|
1015
|
+
while (RARRAY_LEN( ary) > 0 && RTEST( rb_yield( RARRAY_PTR( ary)[ 0])))
|
|
1016
|
+
rb_ary_shift( ary);
|
|
1017
|
+
return RARRAY_LEN( ary) ? ary : Qnil;
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
/*
|
|
1021
|
+
* call-seq:
|
|
1022
|
+
* rstrip! { |elem| ... } -> nil or self
|
|
1023
|
+
*
|
|
1024
|
+
* Strip all elements from left where the block returns a true value.
|
|
1025
|
+
* Returns <code>nil</code> when the array is empty afterwards.
|
|
1026
|
+
*
|
|
1027
|
+
* a = %w(ant bat cow dog eel fox gnu)
|
|
1028
|
+
* a.rstrip! { |e| e =~ /[ou]/ } #=> [ "ant", "bat", "cow", "dog", "eel"]
|
|
1029
|
+
* a.lstrip! { |e| e.length == 3 } #=> nil
|
|
1030
|
+
*/
|
|
1031
|
+
|
|
1032
|
+
VALUE
|
|
1033
|
+
rb_ary_rstrip_bang( VALUE ary)
|
|
1034
|
+
{
|
|
1035
|
+
while (RARRAY_LEN( ary) > 0 && RTEST( rb_yield( RARRAY_PTR( ary)[ RARRAY_LEN(ary)-1])))
|
|
1036
|
+
rb_ary_pop( ary);
|
|
1037
|
+
return RARRAY_LEN( ary) ? ary : Qnil;
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
|
|
1041
|
+
long
|
|
1042
|
+
supplement_find_nth( VALUE ary, VALUE num, VALUE (*mk_result)( VALUE, long, VALUE))
|
|
1043
|
+
{
|
|
1044
|
+
VALUE cur;
|
|
1045
|
+
long i, n;
|
|
1046
|
+
|
|
1047
|
+
n = NUM2LONG( num);
|
|
1048
|
+
for (i = 0; i < RARRAY_LEN( ary); i++) {
|
|
1049
|
+
cur = RARRAY_PTR( ary)[ i];
|
|
1050
|
+
if (RTEST( rb_yield( cur))) {
|
|
1051
|
+
if (!n)
|
|
1052
|
+
return (*mk_result)( ary, i, cur);
|
|
1053
|
+
n--;
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
return Qnil;
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
/*
|
|
1060
|
+
* call-seq:
|
|
1061
|
+
* find_nth( int) { |elem| ... } -> obj or nil
|
|
1062
|
+
*
|
|
1063
|
+
* Find the n-th occurrence of an element for which the block returns
|
|
1064
|
+
* a true value. When less than n elements can be found, <code>nil</code> is
|
|
1065
|
+
* returned.
|
|
1066
|
+
*
|
|
1067
|
+
* a = %w(ant bat cow dog eel fox gnu)
|
|
1068
|
+
* a.find_nth(0) { |e| e =~ /a/ } #=> "ant"
|
|
1069
|
+
* a.find_nth(1) { |e| e =~ /a/ } #=> "bat"
|
|
1070
|
+
* a.find_nth(2) { |e| e =~ /a/ } #=> nil
|
|
1071
|
+
*/
|
|
1072
|
+
|
|
1073
|
+
VALUE
|
|
1074
|
+
rb_ary_find_nth( VALUE ary, VALUE num)
|
|
1075
|
+
{
|
|
1076
|
+
return supplement_find_nth( ary, num, &supplement_find_nth_result);
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
VALUE
|
|
1080
|
+
supplement_find_nth_result( VALUE ary, long i, VALUE cur)
|
|
1081
|
+
{
|
|
1082
|
+
return cur;
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
/*
|
|
1086
|
+
* call-seq:
|
|
1087
|
+
* delete_nth( int) { |elem| ... } -> obj or nil
|
|
1088
|
+
*
|
|
1089
|
+
* Delete the n-th occurrence of an element for which the block returns
|
|
1090
|
+
* a true value. When less than n elements can be found, nothing will be
|
|
1091
|
+
* removed and <code>nil</code> is returned.
|
|
1092
|
+
*
|
|
1093
|
+
* a = %w(ant bat cow dog eel fox gnu)
|
|
1094
|
+
* a.delete_nth(2) { |e| e =~ /a/ } #=> nil
|
|
1095
|
+
* a.delete_nth(1) { |e| e =~ /a/ } #=> "bat"
|
|
1096
|
+
* a.delete_nth(0) { |e| e =~ /a/ } #=> "ant"
|
|
1097
|
+
* a #=> ["cow", "dog", "eel", "fox", "gnu"]
|
|
1098
|
+
*/
|
|
1099
|
+
|
|
1100
|
+
VALUE
|
|
1101
|
+
rb_ary_delete_nth( VALUE ary, VALUE num)
|
|
1102
|
+
{
|
|
1103
|
+
return supplement_find_nth( ary, num, &supplement_delete_nth_result);
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
VALUE
|
|
1107
|
+
supplement_delete_nth_result( VALUE ary, long i, VALUE cur)
|
|
1108
|
+
{
|
|
1109
|
+
return rb_funcall( ary, id_delete_at, 1, LONG2NUM( i));
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
|
|
959
1113
|
/*
|
|
960
1114
|
* Document-class: Hash
|
|
961
1115
|
*/
|
|
@@ -1047,7 +1201,7 @@ supplement_do_unumask( VALUE v)
|
|
|
1047
1201
|
VALUE
|
|
1048
1202
|
rb_dir_s_current( VALUE dir)
|
|
1049
1203
|
{
|
|
1050
|
-
VALUE dot =
|
|
1204
|
+
VALUE dot = SPL_CSTR( supplement_dot);
|
|
1051
1205
|
return rb_funcall_passing_block( dir, rb_intern( "open"), 1, &dot);
|
|
1052
1206
|
}
|
|
1053
1207
|
|
|
@@ -1239,6 +1393,8 @@ void Init_supplement( void)
|
|
|
1239
1393
|
rb_define_method( rb_cObject, "nil_if", rb_obj_nil_if, 1);
|
|
1240
1394
|
rb_define_method( rb_mKernel, "tap!", rb_krn_tap_bang, 0);
|
|
1241
1395
|
|
|
1396
|
+
rb_define_global_const("SUPPLEMENT_VERSION", rb_obj_freeze( SPL_CSTR(SUPPLEMENT_VERSION)));
|
|
1397
|
+
|
|
1242
1398
|
rb_define_method( rb_cModule, "plain_name", rb_module_plain_name, 0);
|
|
1243
1399
|
|
|
1244
1400
|
rb_define_method( rb_cNilClass, "notempty?", rb_nil_notempty_p, 0);
|
|
@@ -1263,6 +1419,8 @@ void Init_supplement( void)
|
|
|
1263
1419
|
rb_define_method( rb_cNumeric, "grammatical", rb_num_grammatical, 2);
|
|
1264
1420
|
rb_define_method( rb_cNumeric, "sqrt", rb_num_sqrt, 0);
|
|
1265
1421
|
|
|
1422
|
+
rb_define_method( rb_cInteger, "length", rb_int_length, -1);
|
|
1423
|
+
|
|
1266
1424
|
rb_define_method( rb_cRational, "inv", rb_rat_inverse, 0);
|
|
1267
1425
|
|
|
1268
1426
|
rb_define_method( rb_cArray, "notempty?", rb_ary_notempty_p, 0);
|
|
@@ -1273,6 +1431,10 @@ void Init_supplement( void)
|
|
|
1273
1431
|
rb_define_method( rb_cArray, "range", rb_ary_range, 0);
|
|
1274
1432
|
rb_define_method( rb_cArray, "pick", rb_ary_pick, -1);
|
|
1275
1433
|
rb_define_method( rb_cArray, "rpick", rb_ary_rpick, -1);
|
|
1434
|
+
rb_define_method( rb_cArray, "lstrip!", rb_ary_lstrip_bang, 0);
|
|
1435
|
+
rb_define_method( rb_cArray, "rstrip!", rb_ary_rstrip_bang, 0);
|
|
1436
|
+
rb_define_method( rb_cArray, "find_nth", rb_ary_find_nth, 1);
|
|
1437
|
+
rb_define_method( rb_cArray, "delete_nth", rb_ary_delete_nth, 1);
|
|
1276
1438
|
|
|
1277
1439
|
rb_define_method( rb_cHash, "notempty?", rb_hash_notempty_p, 0);
|
|
1278
1440
|
|
|
@@ -1288,7 +1450,7 @@ void Init_supplement( void)
|
|
|
1288
1450
|
rb_define_method( rb_cMatch, "begin", rb_match_begin, -1);
|
|
1289
1451
|
rb_define_method( rb_cMatch, "end", rb_match_end, -1);
|
|
1290
1452
|
|
|
1291
|
-
rb_define_alias(
|
|
1453
|
+
rb_define_alias( CLASS_OF( rb_cStruct), "[]", "new");
|
|
1292
1454
|
rb_define_method( rb_cStruct, "fields", rb_struct_fields, -1);
|
|
1293
1455
|
rb_define_alias( rb_cStruct, "fetch_values", "fields");
|
|
1294
1456
|
|
|
@@ -1296,11 +1458,8 @@ void Init_supplement( void)
|
|
|
1296
1458
|
rb_define_method( rb_cFalseClass, "to_bool", rb_nil_to_bool, 0);
|
|
1297
1459
|
rb_define_method( rb_cObject, "to_bool", rb_obj_to_bool, 0);
|
|
1298
1460
|
|
|
1299
|
-
id_delete_at
|
|
1300
|
-
|
|
1301
|
-
id_eqq = 0;
|
|
1302
|
-
id_mkdir = 0;
|
|
1303
|
-
id_index = 0;
|
|
1461
|
+
id_delete_at = rb_intern( "delete_at");
|
|
1462
|
+
id_eqq = rb_intern( "===");
|
|
1304
1463
|
|
|
1305
1464
|
Init_supplement_process();
|
|
1306
1465
|
}
|
data/lib/supplement.h
CHANGED
|
@@ -35,6 +35,7 @@ extern VALUE rb_sym_ends_with_p( int argc, VALUE *argv, VALUE);
|
|
|
35
35
|
|
|
36
36
|
extern VALUE rb_num_grammatical( VALUE, VALUE, VALUE);
|
|
37
37
|
extern VALUE rb_num_sqrt( VALUE);
|
|
38
|
+
extern VALUE rb_int_length( int, VALUE *, VALUE);
|
|
38
39
|
extern VALUE rb_rat_inverse( VALUE);
|
|
39
40
|
|
|
40
41
|
extern VALUE rb_ary_notempty_p( VALUE);
|
|
@@ -44,6 +45,10 @@ extern VALUE rb_ary_indexes( VALUE);
|
|
|
44
45
|
extern VALUE rb_ary_range( VALUE);
|
|
45
46
|
extern VALUE rb_ary_pick( int, VALUE *, VALUE);
|
|
46
47
|
extern VALUE rb_ary_rpick( int, VALUE *, VALUE);
|
|
48
|
+
extern VALUE rb_ary_lstrip_bang( VALUE);
|
|
49
|
+
extern VALUE rb_ary_rstrip_bang( VALUE);
|
|
50
|
+
extern VALUE rb_ary_find_nth( VALUE, VALUE);
|
|
51
|
+
extern VALUE rb_ary_delete_nth( VALUE, VALUE);
|
|
47
52
|
|
|
48
53
|
extern VALUE rb_hash_notempty_p( VALUE);
|
|
49
54
|
|
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.
|
|
4
|
+
version: '2.34'
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bertram Scharpf
|
|
@@ -50,7 +50,6 @@ extra_rdoc_files:
|
|
|
50
50
|
files:
|
|
51
51
|
- LICENSE
|
|
52
52
|
- README.md
|
|
53
|
-
- examples/teatimer
|
|
54
53
|
- lib/Rakefile
|
|
55
54
|
- lib/mkrf_conf
|
|
56
55
|
- lib/process.c
|
data/examples/teatimer
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
|
|
3
|
-
#
|
|
4
|
-
# teatimer -- Countdown timer
|
|
5
|
-
#
|
|
6
|
-
|
|
7
|
-
# This is an example application for the itimer library.
|
|
8
|
-
# Example:
|
|
9
|
-
#
|
|
10
|
-
# $ teatimer 3m play bell.wav
|
|
11
|
-
# # Count down 3 minutes and the exec the player.
|
|
12
|
-
#
|
|
13
|
-
|
|
14
|
-
require "supplement/itimer"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class TeaTimer
|
|
18
|
-
|
|
19
|
-
M = 60
|
|
20
|
-
H = 60 * M
|
|
21
|
-
|
|
22
|
-
class <<self
|
|
23
|
-
|
|
24
|
-
def from_str time
|
|
25
|
-
seconds = case time
|
|
26
|
-
when /m\z/ then Integer( $`) * M
|
|
27
|
-
when /h\z/ then Integer( $`) * H
|
|
28
|
-
else divide_colons time
|
|
29
|
-
end
|
|
30
|
-
new seconds
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def run time
|
|
34
|
-
t = from_str time
|
|
35
|
-
t.run
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
private
|
|
39
|
-
|
|
40
|
-
def divide_colons time
|
|
41
|
-
a = time.split ":", -1
|
|
42
|
-
a.map! { |x| Integer( x) }
|
|
43
|
-
a.reverse!
|
|
44
|
-
r = a.shift
|
|
45
|
-
if a.first then r += M * a.shift end
|
|
46
|
-
if a.first then r += H * a.shift end
|
|
47
|
-
a.empty? or raise "Illegal time spec: #{time}."
|
|
48
|
-
r
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def initialize seconds
|
|
54
|
-
@seconds = seconds
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
class Done < Exception ; end
|
|
58
|
-
|
|
59
|
-
def run
|
|
60
|
-
trap "SIGALRM" do
|
|
61
|
-
@seconds -= 1
|
|
62
|
-
print_rest
|
|
63
|
-
raise Done if @seconds.zero?
|
|
64
|
-
end
|
|
65
|
-
Process.setitimer 1
|
|
66
|
-
print_rest
|
|
67
|
-
sleep
|
|
68
|
-
rescue Done
|
|
69
|
-
puts
|
|
70
|
-
ensure
|
|
71
|
-
trap "SIGALRM", "DEFAULT"
|
|
72
|
-
Process.setitimer nil
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
private
|
|
76
|
-
|
|
77
|
-
def print_rest
|
|
78
|
-
$stdout.print " \r%02d:%02d:%02d" %
|
|
79
|
-
[ @seconds / H, @seconds % H / M, @seconds % M]
|
|
80
|
-
$stdout.flush
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
TeaTimer.run $*.first =~ /\A\d+/ ? $*.shift : "3m"
|
|
86
|
-
exec *$* if $*.any?
|
|
87
|
-
|