supplement 2.33 → 2.35

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: 9a1c02a87bc3156c7468abf0618da0dc18769fc09335605638e62515ebfc4b3c
4
- data.tar.gz: e73d0a28b4f10dafdaea31aa8aa55f85e29db0ecb5d392512ad0429a280a1e1d
3
+ metadata.gz: f1925322fe87c6ca93ad71d6647ed193ab55bd2f3ed9bd7600780a856e9ebf1e
4
+ data.tar.gz: 6cf2009965e72b546d60a1ee549093fe585112085afd1a8f8344db78ef7ebb99
5
5
  SHA512:
6
- metadata.gz: ca470be4d0d6f934d0adc74d249b52a1c682a38928848d03ea78ba3ef564cae49f2de61540b6e886fc8e08340085dacfd55d1516a9eab6bbc2c6dc3bfa227c79
7
- data.tar.gz: 2c00ea6c30f2a6aa3b7f456d05c8f58895b12821590f928263e32e411d151ffe7e702b9b090cb954d677a628a5fc161217675b2a3496ae472230286300a3ca6a
6
+ metadata.gz: b5e76807db2b9e193c7c8f7dfd46a6da96d521ac7c269db7d067d090c171218a6cc89d9fc54cebd1f9f70d23f7bfd29f9952dbac74ba2b0417ed719e041a7698
7
+ data.tar.gz: 2640934aecadd84ff0791f6e709065cd706839f32dc0edb062fb2e1e40e2f72ab1f87c8c30a5f6bb3360b8835729b1d4a9f3df8212659a78fc4b97354d6531fc
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # supplement 2.33 -- Useful Ruby enhancements
1
+ # supplement -- Useful Ruby enhancements
2
2
 
3
3
  Some simple Ruby extensions.
4
4
 
data/lib/supplement.c CHANGED
@@ -11,22 +11,34 @@
11
11
  #include <ruby/re.h>
12
12
 
13
13
 
14
+ #define SUPPLEMENT_VERSION "2.35"
15
+
16
+
17
+
14
18
  static long supplement_args_len_default( int, VALUE *);
15
19
  static void supplement_ary_assure_notempty( VALUE);
16
20
  static VALUE supplement_index_blk( VALUE);
17
21
  static VALUE supplement_index_ref( VALUE, VALUE);
18
22
  static VALUE supplement_rindex_blk( VALUE);
19
23
  static VALUE supplement_rindex_ref( VALUE, VALUE);
24
+ static long supplement_find_nth( VALUE, VALUE, VALUE (*)( VALUE, long, VALUE));
25
+ static VALUE supplement_find_nth_result( VALUE, long, VALUE);
26
+ static VALUE supplement_delete_nth_result( VALUE, long, VALUE);
27
+
20
28
  static VALUE supplement_do_unumask( VALUE);
21
29
 
22
30
 
31
+ static const char *supplement_scope = "::";
23
32
  static const char *supplement_ellipse = "...";
33
+ static const char *supplement_dot = ".";
24
34
 
25
35
  static ID id_delete_at = 0;
26
- static ID id_cmp = 0;
27
- static ID id_eqq = 0;
28
- static ID id_mkdir = 0;
29
- static ID id_index = 0;
36
+ static ID id_eqq = 0;
37
+ static ID id_cmp = 0;
38
+ static ID id_mkdir = 0;
39
+ static ID id_abs = 0;
40
+ static ID id_div = 0;
41
+ static ID id_zero_p = 0;
30
42
 
31
43
 
32
44
 
@@ -81,8 +93,6 @@ rb_obj_new_string( VALUE obj)
81
93
  VALUE
82
94
  rb_obj_nil_if( VALUE obj, VALUE val)
83
95
  {
84
- if (!id_eqq)
85
- id_eqq = rb_intern( "===");
86
96
  return RTEST( rb_funcall( val, id_eqq, 1, obj)) ? Qnil : obj;
87
97
  }
88
98
 
@@ -125,12 +135,14 @@ VALUE
125
135
  rb_module_plain_name( VALUE cls)
126
136
  {
127
137
  VALUE n;
138
+ VALUE c;
128
139
  VALUE i;
129
140
 
130
141
  n = rb_str_dup( rb_funcall( cls, rb_intern( "name"), 0));
131
- i = rb_funcall( n, rb_intern( "rindex"), 1, rb_str_new( "::", 2));
142
+ c = rb_str_new2( supplement_scope);
143
+ i = rb_funcall( n, rb_intern( "rindex"), 1, c);
132
144
  if (!NIL_P( i)) {
133
- i = rb_funcall( i, rb_intern( "+"), 1, INT2FIX( 2));
145
+ i = rb_funcall( i, rb_intern( "+"), 1, LONG2NUM( rb_str_strlen( c)));
134
146
  rb_funcall( n, rb_intern( "slice!"), 2, INT2FIX( 0), i);
135
147
  }
136
148
  return n;
@@ -245,9 +257,7 @@ VALUE
245
257
  rb_str_eat( int argc, VALUE *argv, VALUE str)
246
258
  {
247
259
  VALUE val;
248
- int n;
249
- int l;
250
- int r;
260
+ long n, l, r;
251
261
 
252
262
  n = l = rb_str_strlen( str);
253
263
  if (rb_scan_args( argc, argv, "01", &val) == 1) {
@@ -292,8 +302,7 @@ rb_str_eat( int argc, VALUE *argv, VALUE str)
292
302
  VALUE
293
303
  rb_str_cut_bang( VALUE str, VALUE len)
294
304
  {
295
- int l;
296
- int n;
305
+ long l, n;
297
306
 
298
307
  rb_str_modify( str);
299
308
  l = NUM2INT( len);
@@ -342,7 +351,7 @@ VALUE
342
351
  rb_str_rest( int argc, VALUE *argv, VALUE str)
343
352
  {
344
353
  VALUE n;
345
- long l, beg, len;
354
+ long l, beg;
346
355
 
347
356
  beg = rb_scan_args( argc, argv, "01", &n) == 1 ? NUM2LONG( n) : 1;
348
357
  if (beg < 0)
@@ -456,8 +465,7 @@ rb_str_axe_bang( int argc, VALUE *argv, VALUE str)
456
465
  oldlen = rb_str_strlen( str);
457
466
  if (newlen < oldlen) {
458
467
  VALUE ell;
459
- long le;
460
- long re;
468
+ long le, re;
461
469
 
462
470
  rb_str_update( str, newlen, oldlen - newlen, rb_str_new( NULL, 0));
463
471
  ell = rb_str_new2( supplement_ellipse);
@@ -553,20 +561,9 @@ rb_str_ends_with_p( int argc, VALUE *argv, VALUE str)
553
561
 
554
562
 
555
563
  /*
556
- * call-seq:
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>.
564
+ * Document-class: Symbol
567
565
  */
568
566
 
569
-
570
567
  /*
571
568
  * call-seq:
572
569
  * notempty? -> nil or self
@@ -578,8 +575,8 @@ rb_str_ends_with_p( int argc, VALUE *argv, VALUE str)
578
575
  * :"".notempty? #=> nil
579
576
  *
580
577
  * This seems to be quite useless. Its only purpose is to avoid either type
581
- * detection or error catching if other objects are asked whether they're not
582
- * empty.
578
+ * detection or error catching when other objects are asked whether they're
579
+ * not empty.
583
580
  */
584
581
 
585
582
  VALUE
@@ -668,6 +665,8 @@ rb_num_grammatical( VALUE num, VALUE sing, VALUE plu)
668
665
  break;
669
666
 
670
667
  default:
668
+ if (!id_cmp)
669
+ id_cmp = rb_intern( "<=>");
671
670
  l = NUM2LONG( rb_funcall( num, id_cmp, 1, INT2FIX( 1)));
672
671
  if (l == 0)
673
672
  return sing;
@@ -695,6 +694,47 @@ rb_num_sqrt( VALUE num)
695
694
  return rb_float_new( sqrt( RFLOAT_VALUE( rb_Float( num))));
696
695
  }
697
696
 
697
+
698
+ /*
699
+ * Document-class: Integer
700
+ */
701
+
702
+ /*
703
+ * call-seq:
704
+ * int.length( base = nil) -> int
705
+ *
706
+ * Length of mantissa. Default base is <code>10</code>.
707
+ *
708
+ * 1234.length #=> 4
709
+ */
710
+
711
+ VALUE
712
+ rb_int_length( int argc, VALUE *argv, VALUE num)
713
+ {
714
+ VALUE base;
715
+ VALUE x;
716
+ long n;
717
+
718
+ if (!id_abs)
719
+ id_abs = rb_intern( "abs");
720
+ if (!id_div)
721
+ id_div = rb_intern( "div");
722
+ if (!id_zero_p)
723
+ id_zero_p = rb_intern( "zero?");
724
+
725
+ if (rb_scan_args( argc, argv, "01", &base) != 1)
726
+ base = Qnil;
727
+ if (NIL_P( base))
728
+ base = LONG2NUM( 10);
729
+ n = 0;
730
+ x = rb_funcall( num, id_abs, 0);
731
+ while (!RTEST(rb_funcall( x, id_zero_p, 0))) {
732
+ n++;
733
+ x = rb_funcall( x, id_div, 1, base);
734
+ }
735
+ return LONG2NUM( n);
736
+ }
737
+
698
738
  /*
699
739
  * Document-class: Rational
700
740
  */
@@ -842,8 +882,8 @@ rb_ary_indexes( VALUE ary)
842
882
  * pick( ref) -> obj or nil
843
883
  * pick { |elem| ... } -> obj or nil
844
884
  *
845
- * Deletes the element where first <code>ref === obj</code> is true or the
846
- * <em>block</em> first returns <code>true</code>. The result will be
885
+ * Deletes the element where first <code>ref === obj</code> or the
886
+ * <em>block</em> first returns a true value. The result will be
847
887
  * <code>nil</code> if nothing is found.
848
888
  *
849
889
  * a = %w(ant bat cat dog)
@@ -874,8 +914,6 @@ supplement_index_ref( VALUE ary, VALUE ref)
874
914
  {
875
915
  long i, j;
876
916
 
877
- if (!id_eqq)
878
- id_eqq = rb_intern( "===");
879
917
  for (i = 0, j = RARRAY_LEN( ary); j > 0; i++, j--) {
880
918
  if (RTEST( rb_funcall( ref, id_eqq, 1, RARRAY_PTR( ary)[ i])))
881
919
  return LONG2NUM( i);
@@ -900,8 +938,8 @@ supplement_index_blk( VALUE ary)
900
938
  * rpick( ref) -> obj or nil
901
939
  * rpick { |elem| ... } -> obj or nil
902
940
  *
903
- * Deletes the element where first <code>ref === obj</code> is true or the
904
- * <em>block</em> first returns <code>true</code>. The result will be
941
+ * Deletes the element where first <code>ref === obj</code> or the
942
+ * <em>block</em> first returns a true value. The result will be
905
943
  * <code>nil</code> if nothing is found. Search from right to left.
906
944
  *
907
945
  * a = %w(ant cow bat cat dog)
@@ -932,8 +970,6 @@ supplement_rindex_ref( VALUE ary, VALUE ref)
932
970
  {
933
971
  long i;
934
972
 
935
- if (!id_eqq)
936
- id_eqq = rb_intern( "===");
937
973
  for (i = RARRAY_LEN( ary); i;) {
938
974
  --i;
939
975
  if (RTEST( rb_funcall( ref, id_eqq, 1, RARRAY_PTR( ary)[ i])))
@@ -956,6 +992,119 @@ supplement_rindex_blk( VALUE ary)
956
992
  }
957
993
 
958
994
 
995
+ /*
996
+ * call-seq:
997
+ * lstrip! { |elem| ... } -> nil or self
998
+ *
999
+ * Strip all elements from left where the block returns a true value.
1000
+ * Returns <code>nil</code> when the array is empty afterwards.
1001
+ *
1002
+ * a = %w(ant bat cow dog eel fox gnu)
1003
+ * a.lstrip! { |e| e =~ /a/ } #=> [ "cow", "dog", "eel", "fox", "gnu"]
1004
+ * a.lstrip! { |e| e.length == 3 } #=> nil
1005
+ */
1006
+
1007
+ VALUE
1008
+ rb_ary_lstrip_bang( VALUE ary)
1009
+ {
1010
+ while (RARRAY_LEN( ary) > 0 && RTEST( rb_yield( RARRAY_PTR( ary)[ 0])))
1011
+ rb_ary_shift( ary);
1012
+ return RARRAY_LEN( ary) ? ary : Qnil;
1013
+ }
1014
+
1015
+ /*
1016
+ * call-seq:
1017
+ * rstrip! { |elem| ... } -> nil or self
1018
+ *
1019
+ * Strip all elements from left where the block returns a true value.
1020
+ * Returns <code>nil</code> when the array is empty afterwards.
1021
+ *
1022
+ * a = %w(ant bat cow dog eel fox gnu)
1023
+ * a.rstrip! { |e| e =~ /[ou]/ } #=> [ "ant", "bat", "cow", "dog", "eel"]
1024
+ * a.lstrip! { |e| e.length == 3 } #=> nil
1025
+ */
1026
+
1027
+ VALUE
1028
+ rb_ary_rstrip_bang( VALUE ary)
1029
+ {
1030
+ while (RARRAY_LEN( ary) > 0 && RTEST( rb_yield( RARRAY_PTR( ary)[ RARRAY_LEN(ary)-1])))
1031
+ rb_ary_pop( ary);
1032
+ return RARRAY_LEN( ary) ? ary : Qnil;
1033
+ }
1034
+
1035
+
1036
+ long
1037
+ supplement_find_nth( VALUE ary, VALUE num, VALUE (*mk_result)( VALUE, long, VALUE))
1038
+ {
1039
+ VALUE cur;
1040
+ long i, n;
1041
+
1042
+ n = NUM2LONG( num);
1043
+ for (i = 0; i < RARRAY_LEN( ary); i++) {
1044
+ cur = RARRAY_PTR( ary)[ i];
1045
+ if (RTEST( rb_yield( cur))) {
1046
+ if (!n)
1047
+ return (*mk_result)( ary, i, cur);
1048
+ n--;
1049
+ }
1050
+ }
1051
+ return Qnil;
1052
+ }
1053
+
1054
+ /*
1055
+ * call-seq:
1056
+ * find_nth( int) { |elem| ... } -> obj or nil
1057
+ *
1058
+ * Find the n-th occurrence of an element for which the block returns
1059
+ * a true value. When less than n elements can be found, <code>nil</code> is
1060
+ * returned.
1061
+ *
1062
+ * a = %w(ant bat cow dog eel fox gnu)
1063
+ * a.find_nth(0) { |e| e =~ /a/ } #=> "ant"
1064
+ * a.find_nth(1) { |e| e =~ /a/ } #=> "bat"
1065
+ * a.find_nth(2) { |e| e =~ /a/ } #=> nil
1066
+ */
1067
+
1068
+ VALUE
1069
+ rb_ary_find_nth( VALUE ary, VALUE num)
1070
+ {
1071
+ return supplement_find_nth( ary, num, &supplement_find_nth_result);
1072
+ }
1073
+
1074
+ VALUE
1075
+ supplement_find_nth_result( VALUE ary, long i, VALUE cur)
1076
+ {
1077
+ return cur;
1078
+ }
1079
+
1080
+ /*
1081
+ * call-seq:
1082
+ * delete_nth( int) { |elem| ... } -> obj or nil
1083
+ *
1084
+ * Delete the n-th occurrence of an element for which the block returns
1085
+ * a true value. When less than n elements can be found, nothing will be
1086
+ * removed and <code>nil</code> is returned.
1087
+ *
1088
+ * a = %w(ant bat cow dog eel fox gnu)
1089
+ * a.delete_nth(2) { |e| e =~ /a/ } #=> nil
1090
+ * a.delete_nth(1) { |e| e =~ /a/ } #=> "bat"
1091
+ * a.delete_nth(0) { |e| e =~ /a/ } #=> "ant"
1092
+ * a #=> ["cow", "dog", "eel", "fox", "gnu"]
1093
+ */
1094
+
1095
+ VALUE
1096
+ rb_ary_delete_nth( VALUE ary, VALUE num)
1097
+ {
1098
+ return supplement_find_nth( ary, num, &supplement_delete_nth_result);
1099
+ }
1100
+
1101
+ VALUE
1102
+ supplement_delete_nth_result( VALUE ary, long i, VALUE cur)
1103
+ {
1104
+ return rb_funcall( ary, id_delete_at, 1, LONG2NUM( i));
1105
+ }
1106
+
1107
+
959
1108
  /*
960
1109
  * Document-class: Hash
961
1110
  */
@@ -1047,7 +1196,7 @@ supplement_do_unumask( VALUE v)
1047
1196
  VALUE
1048
1197
  rb_dir_s_current( VALUE dir)
1049
1198
  {
1050
- VALUE dot = rb_str_new( ".", 1);
1199
+ VALUE dot = rb_str_new2( supplement_dot);
1051
1200
  return rb_funcall_passing_block( dir, rb_intern( "open"), 1, &dot);
1052
1201
  }
1053
1202
 
@@ -1239,6 +1388,8 @@ void Init_supplement( void)
1239
1388
  rb_define_method( rb_cObject, "nil_if", rb_obj_nil_if, 1);
1240
1389
  rb_define_method( rb_mKernel, "tap!", rb_krn_tap_bang, 0);
1241
1390
 
1391
+ rb_define_global_const("SUPPLEMENT_VERSION", rb_obj_freeze( rb_str_new2(SUPPLEMENT_VERSION)));
1392
+
1242
1393
  rb_define_method( rb_cModule, "plain_name", rb_module_plain_name, 0);
1243
1394
 
1244
1395
  rb_define_method( rb_cNilClass, "notempty?", rb_nil_notempty_p, 0);
@@ -1263,6 +1414,8 @@ void Init_supplement( void)
1263
1414
  rb_define_method( rb_cNumeric, "grammatical", rb_num_grammatical, 2);
1264
1415
  rb_define_method( rb_cNumeric, "sqrt", rb_num_sqrt, 0);
1265
1416
 
1417
+ rb_define_method( rb_cInteger, "length", rb_int_length, -1);
1418
+
1266
1419
  rb_define_method( rb_cRational, "inv", rb_rat_inverse, 0);
1267
1420
 
1268
1421
  rb_define_method( rb_cArray, "notempty?", rb_ary_notempty_p, 0);
@@ -1273,6 +1426,10 @@ void Init_supplement( void)
1273
1426
  rb_define_method( rb_cArray, "range", rb_ary_range, 0);
1274
1427
  rb_define_method( rb_cArray, "pick", rb_ary_pick, -1);
1275
1428
  rb_define_method( rb_cArray, "rpick", rb_ary_rpick, -1);
1429
+ rb_define_method( rb_cArray, "lstrip!", rb_ary_lstrip_bang, 0);
1430
+ rb_define_method( rb_cArray, "rstrip!", rb_ary_rstrip_bang, 0);
1431
+ rb_define_method( rb_cArray, "find_nth", rb_ary_find_nth, 1);
1432
+ rb_define_method( rb_cArray, "delete_nth", rb_ary_delete_nth, 1);
1276
1433
 
1277
1434
  rb_define_method( rb_cHash, "notempty?", rb_hash_notempty_p, 0);
1278
1435
 
@@ -1288,7 +1445,7 @@ void Init_supplement( void)
1288
1445
  rb_define_method( rb_cMatch, "begin", rb_match_begin, -1);
1289
1446
  rb_define_method( rb_cMatch, "end", rb_match_end, -1);
1290
1447
 
1291
- rb_define_alias( rb_singleton_class( rb_cStruct), "[]", "new");
1448
+ rb_define_alias( CLASS_OF( rb_cStruct), "[]", "new");
1292
1449
  rb_define_method( rb_cStruct, "fields", rb_struct_fields, -1);
1293
1450
  rb_define_alias( rb_cStruct, "fetch_values", "fields");
1294
1451
 
@@ -1296,11 +1453,8 @@ void Init_supplement( void)
1296
1453
  rb_define_method( rb_cFalseClass, "to_bool", rb_nil_to_bool, 0);
1297
1454
  rb_define_method( rb_cObject, "to_bool", rb_obj_to_bool, 0);
1298
1455
 
1299
- id_delete_at = rb_intern( "delete_at");
1300
- id_cmp = rb_intern( "<=>");
1301
- id_eqq = 0;
1302
- id_mkdir = 0;
1303
- id_index = 0;
1456
+ id_delete_at = rb_intern( "delete_at");
1457
+ id_eqq = rb_intern( "===");
1304
1458
 
1305
1459
  Init_supplement_process();
1306
1460
  }
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.33'
4
+ version: '2.35'
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
-