supplement 2.21 → 2.23
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 +2 -1
- data/lib/supplement/date.rb +0 -50
- data/lib/supplement.c +46 -4
- data/lib/supplement.h +2 -0
- metadata +7 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3d7ee6d3e8eb25677cac8471ba79cbf665610dcb9b061b0e79e1ae138b64157
|
4
|
+
data.tar.gz: 5f3753613e05e2878fa31aa81b8bb007e0fe399db578f1ece73ae76744abfba6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28b038bda87536826cab7e3a9451ab73696e8958b687ef25b90a2c3b3a260464f58fecf1e39d9944b60aaa61c12363d3885ef12fe917ee611648418e8a102033
|
7
|
+
data.tar.gz: b91a88ae34b04323ff296bc0c4fa303f729b053f0eb726ecd1d4fabc7c3d59c05dbda042567bfe3e0449d368dbaec80d676f8aaacd2b64b9b471a290a8158ddf
|
data/README
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
= supplement 2.
|
1
|
+
= supplement 2.23 -- 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/date.rb
CHANGED
@@ -72,55 +72,5 @@ class Date
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
def months_forward n
|
76
|
-
res = self
|
77
|
-
n.times { res = res.next_month }
|
78
|
-
res
|
79
|
-
end
|
80
|
-
|
81
|
-
def months_backward n
|
82
|
-
res = self
|
83
|
-
n.times { res = res.prev_month }
|
84
|
-
res
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
|
90
|
-
unless DateTime.method_defined? :to_time then
|
91
|
-
|
92
|
-
class Time
|
93
|
-
def to_time ; self ; end
|
94
|
-
def to_date
|
95
|
-
jd = Date.civil_to_jd year, mon, mday, Date::ITALY
|
96
|
-
hd = Date.jd_to_ajd jd, 0, 0
|
97
|
-
Date.new! hd, 0, Date::ITALY
|
98
|
-
end
|
99
|
-
def to_datetime
|
100
|
-
jd = DateTime.civil_to_jd year, mon, mday, DateTime::ITALY
|
101
|
-
fr = DateTime.time_to_day_fraction hour, min, [sec, 59].min
|
102
|
-
fr += (Rational usec, 86400*1000000000)
|
103
|
-
of = (Rational utc_offset, 86400)
|
104
|
-
hd = DateTime.jd_to_ajd jd, fr, of
|
105
|
-
DateTime.new! hd, of, DateTime::ITALY
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
class Date
|
110
|
-
def to_time ; Time.local year, mon, mday ; end
|
111
|
-
def to_date ; self ; end
|
112
|
-
def to_datetime ; DateTime.new! Date.jd_to_ajd(jd,0,0), @of, @sg ; end
|
113
|
-
end
|
114
|
-
|
115
|
-
class DateTime
|
116
|
-
def to_time
|
117
|
-
(new_offset 0).instance_eval do
|
118
|
-
Time.utc year, mon, mday, hour, min, sec + sec_fraction
|
119
|
-
end.getlocal
|
120
|
-
end
|
121
|
-
def to_date ; Date.new! Date.jd_to_ajd(jd,0,0), 0, @sg ; end
|
122
|
-
def to_datetime ; self ; end
|
123
|
-
end
|
124
|
-
|
125
75
|
end
|
126
76
|
|
data/lib/supplement.c
CHANGED
@@ -508,8 +508,6 @@ rb_str_starts_with_p( VALUE str, VALUE oth)
|
|
508
508
|
char *s, *o;
|
509
509
|
VALUE ost;
|
510
510
|
|
511
|
-
if (!rb_str_comparable( str, oth))
|
512
|
-
return Qnil;
|
513
511
|
ost = rb_string_value( &oth);
|
514
512
|
i = RSTRING_LEN( ost);
|
515
513
|
if (i > RSTRING_LEN( str))
|
@@ -544,8 +542,6 @@ rb_str_ends_with_p( VALUE str, VALUE oth)
|
|
544
542
|
char *s, *o;
|
545
543
|
VALUE ost;
|
546
544
|
|
547
|
-
if (!rb_str_comparable( str, oth))
|
548
|
-
return Qnil;
|
549
545
|
ost = rb_string_value( &oth);
|
550
546
|
i = RSTRING_LEN( ost);
|
551
547
|
if (i > RSTRING_LEN( str))
|
@@ -818,6 +814,50 @@ rb_ary_notempty_p( VALUE ary)
|
|
818
814
|
return RARRAY_LEN( ary) == 0 ? Qnil : ary;
|
819
815
|
}
|
820
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
|
+
RARRAY_ASET(ary, 0, val);
|
836
|
+
return val;
|
837
|
+
}
|
838
|
+
|
839
|
+
/*
|
840
|
+
* call-seq:
|
841
|
+
* last = obj -> obj
|
842
|
+
*
|
843
|
+
* Replace the last element. Equivalent to <code>ary[-1]=</code>.
|
844
|
+
*
|
845
|
+
* a = [ 42, 39, -1]
|
846
|
+
* a.last = 42
|
847
|
+
* a #=> [42, 39, 42]
|
848
|
+
* a.push 266
|
849
|
+
* a.last /= 14
|
850
|
+
* a #=> [42, 39, 42, 19]
|
851
|
+
*/
|
852
|
+
|
853
|
+
VALUE
|
854
|
+
rb_ary_last_set( VALUE ary, VALUE val)
|
855
|
+
{
|
856
|
+
rb_ary_modify(ary);
|
857
|
+
RARRAY_ASET(ary, RARRAY_LEN(ary)-1, val);
|
858
|
+
return val;
|
859
|
+
}
|
860
|
+
|
821
861
|
|
822
862
|
/*
|
823
863
|
* call-seq:
|
@@ -1453,6 +1493,8 @@ void Init_supplement( void)
|
|
1453
1493
|
rb_define_method( rb_cNumeric, "cbrt", rb_num_cbrt, 0);
|
1454
1494
|
|
1455
1495
|
rb_define_method( rb_cArray, "notempty?", rb_ary_notempty_p, 0);
|
1496
|
+
rb_define_method( rb_cArray, "first=", rb_ary_first_set, 1);
|
1497
|
+
rb_define_method( rb_cArray, "last=", rb_ary_last_set, 1);
|
1456
1498
|
rb_define_method( rb_cArray, "indexes", rb_ary_indexes, 0);
|
1457
1499
|
rb_define_alias( rb_cArray, "keys", "indexes");
|
1458
1500
|
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,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: supplement
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '2.
|
4
|
+
version: '2.23'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bertram Scharpf
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-03-10 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: rake
|
@@ -38,9 +37,9 @@ dependencies:
|
|
38
37
|
- - "~>"
|
39
38
|
- !ruby/object:Gem::Version
|
40
39
|
version: '2.18'
|
41
|
-
description:
|
42
|
-
|
43
|
-
|
40
|
+
description: |
|
41
|
+
Simple methods that didn't manage to become
|
42
|
+
part of standard Ruby.
|
44
43
|
email: "<software@bertram-scharpf.de>"
|
45
44
|
executables: []
|
46
45
|
extensions:
|
@@ -71,14 +70,11 @@ files:
|
|
71
70
|
- lib/supplement/socket.h
|
72
71
|
- lib/supplement/terminal.c
|
73
72
|
- lib/supplement/terminal.h
|
74
|
-
homepage:
|
73
|
+
homepage: https://github.com/BertramScharpf/ruby-supplement
|
75
74
|
licenses:
|
76
75
|
- BSD-2-Clause
|
77
76
|
metadata: {}
|
78
|
-
post_install_message:
|
79
77
|
rdoc_options:
|
80
|
-
- "--charset"
|
81
|
-
- utf-8
|
82
78
|
- "--main"
|
83
79
|
- README
|
84
80
|
require_paths:
|
@@ -95,8 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
91
|
version: '0'
|
96
92
|
requirements:
|
97
93
|
- Ruby and the autorake gem
|
98
|
-
rubygems_version: 3.
|
99
|
-
signing_key:
|
94
|
+
rubygems_version: 3.6.4
|
100
95
|
specification_version: 4
|
101
96
|
summary: Simple Ruby extensions
|
102
97
|
test_files: []
|