backports 3.21.0 → 3.22.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 530520a5a0baa3962a2532fde75e3cb3ee2ceac6d3c492dc72a791f8655bf5d5
4
- data.tar.gz: d850950054b40303ba73d92ab1bd1754d40b78df0fbbf4506b4c7ac40e93e2eb
3
+ metadata.gz: b29bdab2282a6e583c683ceb5d2a6665eba385330570cc99ec82935a3fd7156d
4
+ data.tar.gz: 9539d241f8d89982762c21432713d04d13567ce4c9392af5d54b38099e08cc3f
5
5
  SHA512:
6
- metadata.gz: 2de1296503399822ed401d55b4482f7452f12414877564fa09237b349a951edd41bf06959a62498d335c241e13f706d7c59756519924facd599c5dfd3413fa47
7
- data.tar.gz: 25fcaaa2d21ff9bee8b0b3328b0d73b63c451074a22938d26c80ec044b88583be429b2d2b1334f86035afd0880e534b3aca8be9203ebbc74221c71cafa5b0953
6
+ metadata.gz: 6bfa34744270343976ea43ffab74f332e6652b681723cb18d6fa414327c57f994169dfca42efe75bed24a6cdccfeff0bb1c39f0f0ff61b056eb7333dfb514819
7
+ data.tar.gz: 83617fcaa2270b28c3f11ac41cf29a875da9bac572da23381bc990a0d5c452a0f12809114fb98478ad6887136d962a8116da41601f4cfb532065dea88614117a
data/CHANGELOG.md CHANGED
@@ -8,6 +8,12 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
8
8
 
9
9
  Note: [Next major version (X-mas 2021?)](https://github.com/marcandre/backports/issues/139) may drop support for Ruby < 2.2, please comment.
10
10
 
11
+ ## [3.21.0](https://github.com/marcandre/backports/compare/v3.20.1...v3.21.0) - 2021-03-31
12
+
13
+ ### Added
14
+
15
+ * Added `String#unpack1` (Ruby 2.4) [#166]
16
+
11
17
  ## [3.20.1](https://github.com/marcandre/backports/compare/v3.20.0...v3.20.1) - 2021-01-03
12
18
 
13
19
  ### Fixed
data/Gemfile CHANGED
@@ -11,6 +11,6 @@ end
11
11
 
12
12
  if RUBY_VERSION >= '2.4.0'
13
13
  group :development do
14
- gem 'rubocop'
14
+ gem 'rubocop', '<1.13.0'
15
15
  end
16
16
  end
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Backports Library [<img src="https://travis-ci.org/marcandre/backports.svg?branch=master">](https://travis-ci.org/marcandre/backports) [<img src="https://badge.fury.io/rb/backports.svg" alt="Gem Version" />](http://badge.fury.io/rb/backports) [![Tidelift](https://tidelift.com/badges/package/rubygems/backports)](https://tidelift.com/subscription/pkg/rubygems-backports?utm_source=rubygems-backports&utm_medium=referral&utm_campaign=readme)
2
2
 
3
- Yearning to write a gem using some new cool features in Ruby 3.0 while
3
+ Yearning to write a gem using some new cool features in Ruby 3.1 while
4
4
  still supporting Ruby 2.5.x?
5
5
  Have some legacy code in Ruby 1.8 but can't live without `flat_map`?
6
6
 
@@ -38,25 +38,26 @@ This will make sure that Hash responds to `dig`, `fetch_values`, `to_proc` and c
38
38
  ### Up to a specific Ruby version (for quick coding)
39
39
 
40
40
  You can load all backports up to a specific version.
41
- For example, to bring any version of Ruby mostly up to Ruby 3.0.0's standards:
41
+ For example, to bring any version of Ruby mostly up to Ruby 3.1.0's standards:
42
42
 
43
- require 'backports/3.0.0'
43
+ require 'backports/3.1.0'
44
44
 
45
45
  This will bring in all the features of 1.8.7 and many features of Ruby 1.9.x
46
- all the way up to Ruby 3.0.0 (for all versions of Ruby)!
46
+ all the way up to Ruby 3.1.0 (for all versions of Ruby)!
47
47
 
48
48
  You may `require 'backports/latest'` as a
49
49
  shortcut to the latest Ruby version supported.
50
50
 
51
- *Note*: For production / public gems, it is highly recommended you only require
51
+ _Note_: For production / public gems, it is highly recommended you only require
52
52
  the backports you need explicitly.
53
53
 
54
- *Note*: Although I am a Ruby committer, this gem is a personal project and is
54
+ _Note_: Although I am a Ruby committer, this gem is a personal project and is
55
55
  not endorsed by ruby-core.
56
56
 
57
57
  ## What's inside
58
58
 
59
59
  Goals for backported features:
60
+
60
61
  1. Won't break older code
61
62
  2. Pure Ruby (no C extensions)
62
63
  3. Pass [ruby/spec](https://github.com/ruby/spec)
@@ -108,350 +109,464 @@ itself, JRuby and Rubinius.
108
109
 
109
110
  # Complete List of backports
110
111
 
112
+ ## Ruby 3.1 backports
113
+
114
+ #### Array
115
+
116
+ - `intersect?`
117
+
118
+ #### Class
119
+
120
+ - `descendants`
121
+ - `subclasses`
122
+
123
+ #### Enumerable
124
+
125
+ - `compact`
126
+ - `tally` (with hash argument)
127
+
128
+ ### File
129
+
130
+ - `dirname` (with depth argument)
131
+
132
+ #### Integer
133
+
134
+ - `try_convert`
135
+
136
+ #### MatchData
137
+
138
+ - `match`
139
+ - `match_length`
140
+
141
+ #### Struct
142
+
143
+ - `keyword_init?`
144
+
111
145
  ## Ruby 3.0 backports
112
146
 
113
147
  #### Env
114
- - `except`
148
+
149
+ - `except`
115
150
 
116
151
  #### Hash
117
- - `except`
118
- - `transform_keys`, `transform_keys!` (with hash argument)
152
+
153
+ - `except`
154
+ - `transform_keys`, `transform_keys!` (with hash argument)
119
155
 
120
156
  #### Ractor
121
- - All methods, with the caveats:
122
- - uses Ruby's `Thread` internally
123
- - will not raise some errors when `Ractor` would (in particular `Ractor::IsolationError`)
124
- - supported in Ruby 2.0+ only
157
+
158
+ - All methods, with the caveats:
159
+ - uses Ruby's `Thread` internally
160
+ - will not raise some errors when `Ractor` would (in particular `Ractor::IsolationError`)
161
+ - supported in Ruby 2.0+ only
125
162
 
126
163
  #### Symbol
127
- - `name`
164
+
165
+ - `name`
128
166
 
129
167
  ## Ruby 2.7 backports
130
168
 
131
169
  #### Array
132
- - `intersection`
170
+
171
+ - `intersection`
133
172
 
134
173
  #### Comparable
135
- - `clamp` (with range)
174
+
175
+ - `clamp` (with range)
136
176
 
137
177
  #### Complex
138
- - `<=>`
178
+
179
+ - `<=>`
139
180
 
140
181
  #### Enumerable
141
- - `filter_map`
142
- - `tally`
182
+
183
+ - `filter_map`
184
+ - `tally`
143
185
 
144
186
  #### Enumerator
145
- - `produce` (class method)
187
+
188
+ - `produce` (class method)
146
189
 
147
190
  #### Time
148
- - `floor`, `ceil`
191
+
192
+ - `floor`, `ceil`
149
193
 
150
194
  ## Ruby 2.6 backports
151
195
 
152
196
  #### Array
153
- - `difference`, `union`
154
- - `to_h` (with block)
197
+
198
+ - `difference`, `union`
199
+ - `to_h` (with block)
155
200
 
156
201
  #### Enumerable
157
- - `chain`
158
- - `to_h` (with block)
202
+
203
+ - `chain`
204
+ - `to_h` (with block)
159
205
 
160
206
  #### Enumerator::Chain (use Enumerable#chain)
161
207
 
162
208
  #### Hash
163
- - `merge`, `merge!`/`update` (with multiple arguments)
164
- - `to_h` (with block)
209
+
210
+ - `merge`, `merge!`/`update` (with multiple arguments)
211
+ - `to_h` (with block)
165
212
 
166
213
  #### Kernel
167
- - `then`
214
+
215
+ - `then`
168
216
 
169
217
  #### Method
170
- - `<<`, `>>`
218
+
219
+ - `<<`, `>>`
171
220
 
172
221
  #### Proc
173
- - `<<`, `>>`
222
+
223
+ - `<<`, `>>`
174
224
 
175
225
  #### Range
176
- - `cover?` (with `Range` argument)
226
+
227
+ - `cover?` (with `Range` argument)
177
228
 
178
229
  ## Ruby 2.5 backports
179
230
 
180
231
  #### Array
181
- - `append`, `prepend`
232
+
233
+ - `append`, `prepend`
182
234
 
183
235
  #### Dir
184
- - `children`, `each_child`
236
+
237
+ - `children`, `each_child`
185
238
 
186
239
  #### Enumerable
187
- - `any?`, `all?`, `none?`, `one?` (with pattern argument)
240
+
241
+ - `any?`, `all?`, `none?`, `one?` (with pattern argument)
188
242
 
189
243
  #### Hash
190
- - `slice`
191
- - `transform_keys`
244
+
245
+ - `slice`
246
+ - `transform_keys`
192
247
 
193
248
  #### Integer
194
- - `sqrt`
195
- - `allbits?`, `anybits?` and `nobits?`
249
+
250
+ - `sqrt`
251
+ - `allbits?`, `anybits?` and `nobits?`
196
252
 
197
253
  #### Kernel
198
- - `yield_self`
254
+
255
+ - `yield_self`
199
256
 
200
257
  #### Module
201
- - `attr`, `attr_accessor`, `attr_reader`, `attr_writer` (now public)
202
- - `define_method`, `alias_method`, `undef_method`, `remove_method` (now
203
- public)
258
+
259
+ - `attr`, `attr_accessor`, `attr_reader`, `attr_writer` (now public)
260
+ - `define_method`, `alias_method`, `undef_method`, `remove_method` (now
261
+ public)
204
262
 
205
263
  #### String
206
- - `delete_prefix`, `delete_prefix!`
207
- - `delete_suffix`, `delete_suffix!`
208
- - `undump`
264
+
265
+ - `delete_prefix`, `delete_prefix!`
266
+ - `delete_suffix`, `delete_suffix!`
267
+ - `undump`
209
268
 
210
269
  #### Struct
211
- - `new` (with `keyword_init: true`)
270
+
271
+ - `new` (with `keyword_init: true`)
212
272
 
213
273
  ## Ruby 2.4 backports
214
274
 
215
275
  #### Comparable
216
- - `clamp`
276
+
277
+ - `clamp`
217
278
 
218
279
  #### Enumerable
219
- - `sum`
220
- - `uniq`
280
+
281
+ - `sum`
282
+ - `uniq`
221
283
 
222
284
  #### Hash
223
- - `compact`, `compact!`
224
- - `transform_values`, `transform_values!`
285
+
286
+ - `compact`, `compact!`
287
+ - `transform_values`, `transform_values!`
225
288
 
226
289
  #### Queue
227
- - `close`, `closed?`
290
+
291
+ - `close`, `closed?`
228
292
 
229
293
  #### Regexp
230
- - `match?`
294
+
295
+ - `match?`
231
296
 
232
297
  #### String
233
- - `match?`
234
- - `unpack1`
298
+
299
+ - `match?`
300
+ - `unpack1`
235
301
 
236
302
  #### FalseClass, Fixnum, Bignum, Float, NilClass, TrueClass
237
- - `dup`
303
+
304
+ - `dup`
238
305
 
239
306
  ## Ruby 2.3 backports
240
307
 
241
308
  #### Array
242
- - `bsearch_index`
243
- - `dig`
309
+
310
+ - `bsearch_index`
311
+ - `dig`
244
312
 
245
313
  #### Enumerable
246
- - `chunk_while`
247
- - `grep_v`
314
+
315
+ - `chunk_while`
316
+ - `grep_v`
248
317
 
249
318
  #### Hash
250
- - `dig`
251
- - `fetch_values`
252
- - `to_proc`
253
- - <=, <, >=, >
319
+
320
+ - `dig`
321
+ - `fetch_values`
322
+ - `to_proc`
323
+ - <=, <, >=, >
254
324
 
255
325
  #### Numeric
256
- - `negative?`
257
- - `positive?`
326
+
327
+ - `negative?`
328
+ - `positive?`
258
329
 
259
330
  #### String
260
- - unary + and -
331
+
332
+ - unary + and -
261
333
 
262
334
  #### Struct
263
- - `dig`
335
+
336
+ - `dig`
264
337
 
265
338
  ## Ruby 2.2 backports
266
339
 
267
340
  #### Enumerable
268
- - `slice_after`
269
- - `slice_when`
341
+
342
+ - `slice_after`
343
+ - `slice_when`
270
344
 
271
345
  #### Float
272
- - `prev_float`
273
- - `next_float`
346
+
347
+ - `prev_float`
348
+ - `next_float`
274
349
 
275
350
  #### Kernel
276
- - `itself`
351
+
352
+ - `itself`
277
353
 
278
354
  #### Method
279
- - `curry`
280
- - `super_method`
355
+
356
+ - `curry`
357
+ - `super_method`
281
358
 
282
359
  #### String
283
- - `unicode_normalize`
284
- - `unicode_normalize!`
285
- - `unicode_normalize?`
360
+
361
+ - `unicode_normalize`
362
+ - `unicode_normalize!`
363
+ - `unicode_normalize?`
286
364
 
287
365
  ## Ruby 2.1 backports
288
366
 
289
367
  #### Array
290
- - `to_h`
368
+
369
+ - `to_h`
291
370
 
292
371
  #### Bignum
293
- - `bit_length`
372
+
373
+ - `bit_length`
294
374
 
295
375
  #### Enumerable
296
- - `to_h`
376
+
377
+ - `to_h`
297
378
 
298
379
  #### Fixnum
299
- - `bit_length`
380
+
381
+ - `bit_length`
300
382
 
301
383
  #### Module
302
- - `include` (now public)
384
+
385
+ - `include` (now public)
386
+ - `singleton_class?`
303
387
 
304
388
  ## Ruby 2.0 backports
305
389
 
306
390
  #### Array
307
- - `bsearch`
391
+
392
+ - `bsearch`
308
393
 
309
394
  #### Enumerable
310
- - `lazy`
395
+
396
+ - `lazy`
311
397
 
312
398
  #### Enumerator::Lazy
313
- - all methods
399
+
400
+ - all methods
314
401
 
315
402
  #### Hash
316
- - `default_proc=` (with nil argument)
317
- - `to_h`
403
+
404
+ - `default_proc=` (with nil argument)
405
+ - `to_h`
318
406
 
319
407
  #### `nil.to_h`
320
408
 
321
409
  #### Range
322
- - `bsearch`
410
+
411
+ - `bsearch`
323
412
 
324
413
  #### Struct
325
- - `to_h`
414
+
415
+ - `to_h`
326
416
 
327
417
  ## Ruby 1.9.3 backports
328
418
 
329
419
  #### File
330
- - `NULL`
420
+
421
+ - `NULL`
331
422
 
332
423
  #### IO
333
- - `advise` (acts as a noop)
334
- - `write`, `binwrite`
424
+
425
+ - `advise` (acts as a noop)
426
+ - `write`, `binwrite`
335
427
 
336
428
  #### String
337
- - `byteslice`
338
- - `prepend`
429
+
430
+ - `byteslice`
431
+ - `prepend`
339
432
 
340
433
  ## Ruby 1.9.2 backports
341
434
 
342
435
  #### Array
343
- - `rotate, rotate!`
344
- - `keep_if, select!`
345
- - `product` (with block)
346
- - `repeated_combination`, `repeated_permutation`
347
- - `sort_by!`
348
- - `uniq, uniq!` (with block)
436
+
437
+ - `rotate, rotate!`
438
+ - `keep_if, select!`
439
+ - `product` (with block)
440
+ - `repeated_combination`, `repeated_permutation`
441
+ - `sort_by!`
442
+ - `uniq, uniq!` (with block)
349
443
 
350
444
  #### Complex
351
- - `to_r`
445
+
446
+ - `to_r`
352
447
 
353
448
  #### Dir
354
- - `home`
449
+
450
+ - `home`
355
451
 
356
452
  #### Enumerable
357
- - `chunk`
358
- - `flat_map`, `collect_concat`
359
- - `join`
360
- - `slice_before`
453
+
454
+ - `chunk`
455
+ - `flat_map`, `collect_concat`
456
+ - `join`
457
+ - `slice_before`
361
458
 
362
459
  #### Float::INFINITY, NAN
363
460
 
364
461
  #### Hash
365
- - `keep_if`, `select!`
462
+
463
+ - `keep_if`, `select!`
366
464
 
367
465
  #### Object
368
- - `singleton_class`
466
+
467
+ - `singleton_class`
369
468
 
370
469
  #### Random (new class)
371
470
 
372
- *Note*: The methods of `Random` can't be required individually; the class
471
+ _Note_: The methods of `Random` can't be required individually; the class
373
472
  can only be required whole with `require 'backports/1.9.2/random'`.
374
473
 
375
474
  ## Ruby 1.9.1 backports
376
475
 
377
476
  Additionally, the following Ruby 1.9 features have been backported:
477
+
378
478
  #### Array
379
- - `try_convert`
380
- - `sample`
479
+
480
+ - `try_convert`
481
+ - `sample`
381
482
 
382
483
  #### Enumerable
383
- - `each_with_object`
384
- - `each_with_index` (with arguments)
484
+
485
+ - `each_with_object`
486
+ - `each_with_index` (with arguments)
385
487
 
386
488
  #### Enumerator
387
- - `new` (with block)
489
+
490
+ - `new` (with block)
388
491
 
389
492
  #### File
390
- - `binread`
391
- - `to_path`
392
- - All class methods accepting filenames will accept files or anything
393
- with a `#to_path` method.
394
- - `File.open` accepts an options hash.
493
+
494
+ - `binread`
495
+ - `to_path`
496
+ - All class methods accepting filenames will accept files or anything
497
+ with a `#to_path` method.
498
+ - `File.open` accepts an options hash.
395
499
 
396
500
  #### Float
397
- - `round`
501
+
502
+ - `round`
398
503
 
399
504
  #### Hash
400
- - `assoc`, `rassoc`
401
- - `key`
402
- - `try_convert`
403
- - `default_proc=`
505
+
506
+ - `assoc`, `rassoc`
507
+ - `key`
508
+ - `try_convert`
509
+ - `default_proc=`
404
510
 
405
511
  #### Integer
406
- - `magnitude`
407
- - `round`
512
+
513
+ - `magnitude`
514
+ - `round`
408
515
 
409
516
  #### IO
410
- - `bin_read`
411
- - `try_convert`
412
- - `ungetbyte`
413
- - `IO.open` accepts an options hash.
517
+
518
+ - `bin_read`
519
+ - `try_convert`
520
+ - `ungetbyte`
521
+ - `IO.open` accepts an options hash.
414
522
 
415
523
  #### Kernel
416
- - `require_relative`
524
+
525
+ - `require_relative`
417
526
 
418
527
  #### Math
419
- - `log` (with base)
420
- - `log2`
528
+
529
+ - `log` (with base)
530
+ - `log2`
421
531
 
422
532
  #### Numeric
423
- - `round`
533
+
534
+ - `round`
424
535
 
425
536
  #### Object
426
- - `define_singleton_method`
427
- - `public_method`
428
- - `public_send`
537
+
538
+ - `define_singleton_method`
539
+ - `public_method`
540
+ - `public_send`
429
541
 
430
542
  #### Proc
431
- - `yield`
432
- - `lambda?`
433
- - `curry`
434
- - `===`
543
+
544
+ - `yield`
545
+ - `lambda?`
546
+ - `curry`
547
+ - `===`
435
548
 
436
549
  #### Range
437
- - `cover?`
550
+
551
+ - `cover?`
438
552
 
439
553
  #### Regexp
440
- - `try_convert`
554
+
555
+ - `try_convert`
441
556
 
442
557
  #### String
443
- - `ascii_only?`
444
- - `chr`
445
- - `clear`
446
- - `codepoints`, `each_codepoint`
447
- - `get_byte`, `set_byte`
448
- - `ord`
449
- - `try_convert`
558
+
559
+ - `ascii_only?`
560
+ - `chr`
561
+ - `clear`
562
+ - `codepoints`, `each_codepoint`
563
+ - `get_byte`, `set_byte`
564
+ - `ord`
565
+ - `try_convert`
450
566
 
451
567
  `Enumerator` can be accessed directly (instead of `Enumerable::Enumerator`)
452
568
 
453
- To include *only* these backports and those of the 1.8 line, `require
454
- "backports/1.9.1"`.
569
+ To include _only_ these backports and those of the 1.8 line, `require "backports/1.9.1"`.
455
570
 
456
571
  Moreover, a pretty good imitation of `BasicObject` is available, but since it
457
572
  is only an imitation, it must be required explicitly:
@@ -465,8 +580,11 @@ Complete Ruby 1.8.7 backporting (core language). Refer to the official list of
465
580
  backports!
466
581
 
467
582
  Only exceptions:
583
+
468
584
  #### String#gsub (the form returning an enumerator)
469
- #### GC.stress= (not implemented)
585
+
586
+ #### GC.stress= (not implemented)
587
+
470
588
  #### Array#choice (removed in 1.9, use 1.9.1's Array#sample instead)
471
589
 
472
590
  ## Libraries
@@ -478,7 +596,9 @@ The backports would be automatically used after requiring 'backports/std_lib' bu
478
596
  The following libraries are up to date with Ruby 1.9.3:
479
597
 
480
598
  #### Matrix
599
+
481
600
  #### Prime
601
+
482
602
  #### Set
483
603
 
484
604
  The following library is to date with Ruby 2.0.0:
@@ -489,6 +609,7 @@ I am aware of the following backport gem, which probably won't make it into
489
609
  this gem:
490
610
 
491
611
  #### Net::SMTP for Ruby 1.8.6:
612
+
492
613
  [smtp_tls](http://seattlerb.rubyforge.org/smtp_tls/)
493
614
 
494
615
  Requiring backports for a given version of Ruby will also load
@@ -501,13 +622,16 @@ but could be useful in some projects. It is possible to request such
501
622
  incompatible changes. Backports currently supports the following:
502
623
 
503
624
  #### Hash
504
- - `select` (returns a Hash instead of an Array)
625
+
626
+ - `select` (returns a Hash instead of an Array)
505
627
 
506
628
  #### Enumerable / Array
507
- - `map` (returns an enumerator when called without a block)
629
+
630
+ - `map` (returns an enumerator when called without a block)
508
631
 
509
632
  #### String
510
- - `length`, `size` (for UTF-8 support)
633
+
634
+ - `length`, `size` (for UTF-8 support)
511
635
 
512
636
  These must be imported in addition to the backports gem, for example:
513
637
 
@@ -519,8 +643,11 @@ These must be imported in addition to the backports gem, for example:
519
643
  Thanks for the bug reports and patches, in particular the repeat offenders:
520
644
 
521
645
  #### Arto Bendiken ( [bendiken](http://github.com/bendiken) )
646
+
522
647
  #### Konstantin Haase ( [rkh](https://github.com/rkh) )
648
+
523
649
  #### Roger Pack ( [rdp](http://github.com/rdp) )
650
+
524
651
  #### Victor Shepelev ( [zverok](http://github.com/zverok) )
525
652
 
526
653
  ## Contributing
@@ -546,5 +673,4 @@ Failures that are acceptable are added the to `tags` file.
546
673
  LICENSE file.
547
674
 
548
675
  Author
549
- : Marc-André Lafortune
550
-
676
+ : Marc-André Lafortune
@@ -0,0 +1,8 @@
1
+ if Module.method_defined? :singleton_class?
2
+ class Module
3
+ def singleton_class?
4
+ # Hacky...
5
+ inspect.start_with? '#<Class:#'
6
+ end
7
+ end
8
+ end
@@ -1,6 +1,8 @@
1
1
  unless Struct.method_defined? :dig
2
2
  class Struct
3
3
  def dig(key, *rest)
4
+ return self[key] if key.respond_to?(:to_int)
5
+
4
6
  return nil unless respond_to?(key)
5
7
  val = public_send(key)
6
8
  return val if rest.empty? || val == nil
@@ -3,4 +3,8 @@ class Dir
3
3
  def self.children(*args)
4
4
  entries(*args) - Backports::EXCLUDED_CHILDREN
5
5
  end
6
+
7
+ def children
8
+ self.class.children(path)
9
+ end
6
10
  end unless Dir.respond_to? :children
@@ -4,4 +4,11 @@ class Dir
4
4
  return to_enum(__method__, *args) unless block_given?
5
5
  foreach(*args) { |f| yield f unless Backports::EXCLUDED_CHILDREN.include? f }
6
6
  end
7
+
8
+ def each_child(&block)
9
+ return to_enum(__method__) unless block_given?
10
+
11
+ Dir.each_child(path, &block)
12
+ self
13
+ end
7
14
  end unless Dir.respond_to? :each_child
@@ -1,10 +1,11 @@
1
- require 'backports/1.9.1/enumerable/each_with_object' unless Enumerable.method_defined? :each_with_object
2
-
3
1
  unless Enumerable.method_defined? :tally
4
2
  module Enumerable
5
3
  def tally
4
+ h = {}
6
5
  # NB: By spec, tally should return default-less hash
7
- each_with_object(Hash.new(0)) { |item, res| res[item] += 1 }.tap { |h| h.default = nil }
6
+ each_entry { |item| h[item] = h.fetch(item, 0) + 1 }
7
+
8
+ h
8
9
  end
9
10
  end
10
11
  end
@@ -0,0 +1,16 @@
1
+ unless Array.method_defined? :intersect?
2
+ require 'backports/tools/arguments'
3
+
4
+ class Array
5
+ def intersect?(array)
6
+ array = Backports.coerce_to_ary(array)
7
+
8
+ if size < array.size
9
+ smaller = self
10
+ else
11
+ smaller, array = array, self
12
+ end
13
+ (array & smaller).size > 0
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ require 'backports/tools/require_relative_dir'
2
+
3
+ Backports.require_relative_dir
@@ -0,0 +1,11 @@
1
+ unless Class.method_defined? :descendants
2
+ require 'backports/2.1.0/module/singleton_class'
3
+
4
+ class Class
5
+ def descendants
6
+ ObjectSpace.each_object(singleton_class).reject do |klass|
7
+ klass.singleton_class? || klass == self
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ unless Class.method_defined? :subclasses
2
+ require 'backports/2.1.0/module/singleton_class'
3
+
4
+ class Class
5
+ def subclasses
6
+ ObjectSpace.each_object(singleton_class).reject do |klass|
7
+ klass.superclass != self || klass.singleton_class?
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ require 'backports/tools/require_relative_dir'
2
+
3
+ Backports.require_relative_dir
@@ -0,0 +1,5 @@
1
+ module Enumerable
2
+ def compact
3
+ reject { |elem| nil == elem }
4
+ end
5
+ end unless Enumerable.method_defined? :compact
@@ -0,0 +1,18 @@
1
+ unless ([].tally({}) rescue false)
2
+ require 'backports/tools/arguments'
3
+ require 'backports/2.7.0/enumerable/tally'
4
+ require 'backports/tools/alias_method_chain'
5
+
6
+ module Enumerable
7
+ def tally_with_hash_argument(h = ::Backports::Undefined)
8
+ return tally_without_hash_argument if h.equal? ::Backports::Undefined
9
+
10
+ h = ::Backports.coerce_to_hash(h)
11
+
12
+ each_entry { |item| h[item] = h.fetch(item, 0) + 1 }
13
+
14
+ h
15
+ end
16
+ ::Backports.alias_method_chain self, :tally, :hash_argument
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ require 'backports/tools/require_relative_dir'
2
+
3
+ Backports.require_relative_dir
@@ -0,0 +1,16 @@
1
+ unless (File.dirname("", 0) rescue false)
2
+ require 'backports/tools/alias_method_chain'
3
+
4
+ class File
5
+ def self.dirname_with_depth(path, depth = 1)
6
+ return dirname_without_depth(path) if depth == 1
7
+
8
+ raise ArgumentError, "negative depth #{depth}" if depth < 0
9
+
10
+ depth.times { path = dirname_without_depth(path) }
11
+
12
+ path
13
+ end
14
+ Backports.alias_method_chain singleton_class, :dirname, :depth
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ require 'backports/tools/require_relative_dir'
2
+
3
+ Backports.require_relative_dir
@@ -0,0 +1,5 @@
1
+ module Integer
2
+ def self.try_convert(obj)
3
+ ::Backports.try_convert(obj, ::Integer, :to_int)
4
+ end
5
+ end unless Integer.respond_to? :try_convert
@@ -0,0 +1,3 @@
1
+ require 'backports/tools/require_relative_dir'
2
+
3
+ Backports.require_relative_dir
@@ -0,0 +1,5 @@
1
+ class MatchData
2
+ def match(index)
3
+ self[index]
4
+ end
5
+ end unless MatchData.method_defined? :match
@@ -0,0 +1,6 @@
1
+ class MatchData
2
+ def match_length(index)
3
+ m = self[index]
4
+ m && m.length
5
+ end
6
+ end unless MatchData.method_defined? :match_length
@@ -0,0 +1,3 @@
1
+ require 'backports/tools/require_relative_dir'
2
+
3
+ Backports.require_relative_dir
@@ -0,0 +1,5 @@
1
+ unless Struct.respond_to?(:keyword_init?)
2
+ def Struct.keyword_init?
3
+ new(1) && false rescue true
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ require 'backports/tools/require_relative_dir'
2
+
3
+ Backports.require_relative_dir
@@ -0,0 +1,3 @@
1
+ # require this file to load all the backports up to Ruby 3.0
2
+ require 'backports/3.0.0'
3
+ Backports.require_relative_dir if RUBY_VERSION < '3.1'
@@ -0,0 +1 @@
1
+ require 'backports/3.1.0'
@@ -1,4 +1,4 @@
1
1
  # require this file to load all the backports
2
2
  # NOTE: This is NOT recommended.
3
3
  # Best to require the specific backports you need
4
- require 'backports/2.7.0'
4
+ require 'backports/3.1.0'
@@ -1,3 +1,3 @@
1
1
  module Backports
2
- VERSION = "3.21.0" unless Backports.constants.include? :VERSION # the guard is against a redefinition warning that happens on Travis
2
+ VERSION = "3.22.0" unless Backports.constants.include? :VERSION # the guard is against a redefinition warning that happens on Travis
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backports
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.21.0
4
+ version: 3.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc-André Lafortune
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-31 00:00:00.000000000 Z
11
+ date: 2021-12-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Essential backports that enable many of the nice features of Ruby for
14
14
  earlier versions.
@@ -391,6 +391,7 @@ files:
391
391
  - lib/backports/2.1.0/fixnum/bit_length.rb
392
392
  - lib/backports/2.1.0/module.rb
393
393
  - lib/backports/2.1.0/module/include.rb
394
+ - lib/backports/2.1.0/module/singleton_class.rb
394
395
  - lib/backports/2.1.rb
395
396
  - lib/backports/2.2.0.rb
396
397
  - lib/backports/2.2.0/enumerable.rb
@@ -524,7 +525,7 @@ files:
524
525
  - lib/backports/2.7.0/comparable.rb
525
526
  - lib/backports/2.7.0/comparable/clamp.rb
526
527
  - lib/backports/2.7.0/complex.rb
527
- - lib/backports/2.7.0/complex/comparision.rb
528
+ - lib/backports/2.7.0/complex/comparison.rb
528
529
  - lib/backports/2.7.0/enumerable.rb
529
530
  - lib/backports/2.7.0/enumerable/filter_map.rb
530
531
  - lib/backports/2.7.0/enumerable/tally.rb
@@ -543,6 +544,25 @@ files:
543
544
  - lib/backports/3.0.0/symbol.rb
544
545
  - lib/backports/3.0.0/symbol/name.rb
545
546
  - lib/backports/3.0.rb
547
+ - lib/backports/3.1.0.rb
548
+ - lib/backports/3.1.0/array.rb
549
+ - lib/backports/3.1.0/array/intersect.rb
550
+ - lib/backports/3.1.0/class.rb
551
+ - lib/backports/3.1.0/class/descendants.rb
552
+ - lib/backports/3.1.0/class/subclasses.rb
553
+ - lib/backports/3.1.0/enumerable.rb
554
+ - lib/backports/3.1.0/enumerable/compact.rb
555
+ - lib/backports/3.1.0/enumerable/tally.rb
556
+ - lib/backports/3.1.0/file.rb
557
+ - lib/backports/3.1.0/file/dirname.rb
558
+ - lib/backports/3.1.0/integer.rb
559
+ - lib/backports/3.1.0/integer/try_convert.rb
560
+ - lib/backports/3.1.0/match_data.rb
561
+ - lib/backports/3.1.0/match_data/match.rb
562
+ - lib/backports/3.1.0/match_data/match_length.rb
563
+ - lib/backports/3.1.0/struct.rb
564
+ - lib/backports/3.1.0/struct/keyword_init.rb
565
+ - lib/backports/3.1.rb
546
566
  - lib/backports/basic_object.rb
547
567
  - lib/backports/force/array_map.rb
548
568
  - lib/backports/force/enumerable_map.rb
@@ -605,7 +625,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
605
625
  - !ruby/object:Gem::Version
606
626
  version: '0'
607
627
  requirements: []
608
- rubygems_version: 3.2.3
628
+ rubygems_version: 3.1.4
609
629
  signing_key:
610
630
  specification_version: 4
611
631
  summary: Backports of Ruby features for older Ruby.