backports 3.20.1 → 3.22.1

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 (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/Gemfile +1 -1
  4. data/README.md +281 -158
  5. data/lib/backports/2.1.0/module/singleton_class.rb +8 -0
  6. data/lib/backports/2.3.0/struct/dig.rb +2 -0
  7. data/lib/backports/2.4.0/string/unpack1.rb +7 -0
  8. data/lib/backports/2.5.0/dir/children.rb +4 -0
  9. data/lib/backports/2.5.0/dir/each_child.rb +7 -0
  10. data/lib/backports/2.5.0/integer/sqrt.rb +1 -1
  11. data/lib/backports/2.7.0/complex/{comparision.rb → comparison.rb} +0 -0
  12. data/lib/backports/2.7.0/enumerable/tally.rb +4 -3
  13. data/lib/backports/3.0.0/ractor.rb +15 -1
  14. data/lib/backports/3.1.0/array/intersect.rb +16 -0
  15. data/lib/backports/3.1.0/array.rb +3 -0
  16. data/lib/backports/3.1.0/class/descendants.rb +11 -0
  17. data/lib/backports/3.1.0/class/subclasses.rb +11 -0
  18. data/lib/backports/3.1.0/class.rb +3 -0
  19. data/lib/backports/3.1.0/enumerable/compact.rb +5 -0
  20. data/lib/backports/3.1.0/enumerable/tally.rb +18 -0
  21. data/lib/backports/3.1.0/enumerable.rb +3 -0
  22. data/lib/backports/3.1.0/file/dirname.rb +16 -0
  23. data/lib/backports/3.1.0/file.rb +3 -0
  24. data/lib/backports/3.1.0/match_data/match.rb +5 -0
  25. data/lib/backports/3.1.0/match_data/match_length.rb +6 -0
  26. data/lib/backports/3.1.0/match_data.rb +3 -0
  27. data/lib/backports/3.1.0/struct/keyword_init.rb +5 -0
  28. data/lib/backports/3.1.0/struct.rb +3 -0
  29. data/lib/backports/3.1.0.rb +3 -0
  30. data/lib/backports/3.1.rb +1 -0
  31. data/lib/backports/latest.rb +1 -1
  32. data/lib/backports/ractor/cloner.rb +81 -69
  33. data/lib/backports/ractor/errors.rb +14 -10
  34. data/lib/backports/{tools → ractor}/filtered_queue.rb +11 -8
  35. data/lib/backports/ractor/queues.rb +50 -46
  36. data/lib/backports/ractor/ractor.rb +224 -213
  37. data/lib/backports/ractor/sharing.rb +75 -71
  38. data/lib/backports/version.rb +1 -1
  39. metadata +23 -4
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 use 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,349 +109,460 @@ 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
+ #### MatchData
133
+
134
+ - `match`
135
+ - `match_length`
136
+
137
+ #### Struct
138
+
139
+ - `keyword_init?`
140
+
111
141
  ## Ruby 3.0 backports
112
142
 
113
143
  #### Env
114
- - `except`
144
+
145
+ - `except`
115
146
 
116
147
  #### Hash
117
- - `except`
118
- - `transform_keys`, `transform_keys!` (with hash argument)
148
+
149
+ - `except`
150
+ - `transform_keys`, `transform_keys!` (with hash argument)
119
151
 
120
152
  #### 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
153
+
154
+ - All methods, with the caveats:
155
+ - uses Ruby's `Thread` internally
156
+ - will not raise some errors when `Ractor` would (in particular `Ractor::IsolationError`)
157
+ - supported in Ruby 2.0+ only
125
158
 
126
159
  #### Symbol
127
- - `name`
160
+
161
+ - `name`
128
162
 
129
163
  ## Ruby 2.7 backports
130
164
 
131
165
  #### Array
132
- - `intersection`
166
+
167
+ - `intersection`
133
168
 
134
169
  #### Comparable
135
- - `clamp` (with range)
170
+
171
+ - `clamp` (with range)
136
172
 
137
173
  #### Complex
138
- - +<=>+
174
+
175
+ - `<=>`
139
176
 
140
177
  #### Enumerable
141
- - `filter_map`
142
- - `tally`
178
+
179
+ - `filter_map`
180
+ - `tally`
143
181
 
144
182
  #### Enumerator
145
- - `produce` (class method)
183
+
184
+ - `produce` (class method)
146
185
 
147
186
  #### Time
148
- - `floor`, `ceil`
187
+
188
+ - `floor`, `ceil`
149
189
 
150
190
  ## Ruby 2.6 backports
151
191
 
152
192
  #### Array
153
- - `difference`, `union`
154
- - `to_h` (with block)
193
+
194
+ - `difference`, `union`
195
+ - `to_h` (with block)
155
196
 
156
197
  #### Enumerable
157
- - `chain`
158
- - `to_h` (with block)
198
+
199
+ - `chain`
200
+ - `to_h` (with block)
159
201
 
160
202
  #### Enumerator::Chain (use Enumerable#chain)
161
203
 
162
204
  #### Hash
163
- - `merge`, `merge!`/`update` (with multiple arguments)
164
- - `to_h` (with block)
205
+
206
+ - `merge`, `merge!`/`update` (with multiple arguments)
207
+ - `to_h` (with block)
165
208
 
166
209
  #### Kernel
167
- - `then`
210
+
211
+ - `then`
168
212
 
169
213
  #### Method
170
- - +<<+, +>>+
214
+
215
+ - `<<`, `>>`
171
216
 
172
217
  #### Proc
173
- - +<<+, +>>+
218
+
219
+ - `<<`, `>>`
174
220
 
175
221
  #### Range
176
- - `cover?` (with `Range` argument)
222
+
223
+ - `cover?` (with `Range` argument)
177
224
 
178
225
  ## Ruby 2.5 backports
179
226
 
180
227
  #### Array
181
- - `append`, `prepend`
228
+
229
+ - `append`, `prepend`
182
230
 
183
231
  #### Dir
184
- - `children`, `each_child`
232
+
233
+ - `children`, `each_child`
185
234
 
186
235
  #### Enumerable
187
- - `any?`, `all?`, `none?`, `one?` (with pattern argument)
236
+
237
+ - `any?`, `all?`, `none?`, `one?` (with pattern argument)
188
238
 
189
239
  #### Hash
190
- - `slice`
191
- - `transform_keys`
240
+
241
+ - `slice`
242
+ - `transform_keys`
192
243
 
193
244
  #### Integer
194
- - `sqrt`
195
- - `allbits?`, `anybits?` and `nobits?`
245
+
246
+ - `sqrt`
247
+ - `allbits?`, `anybits?` and `nobits?`
196
248
 
197
249
  #### Kernel
198
- - `yield_self`
250
+
251
+ - `yield_self`
199
252
 
200
253
  #### Module
201
- - `attr`, `attr_accessor`, `attr_reader`, `attr_writer` (now public)
202
- - `define_method`, `alias_method`, `undef_method`, `remove_method` (now
203
- public)
254
+
255
+ - `attr`, `attr_accessor`, `attr_reader`, `attr_writer` (now public)
256
+ - `define_method`, `alias_method`, `undef_method`, `remove_method` (now
257
+ public)
204
258
 
205
259
  #### String
206
- - `delete_prefix`, `delete_prefix!`
207
- - `delete_suffix`, `delete_suffix!`
208
- - `undump`
260
+
261
+ - `delete_prefix`, `delete_prefix!`
262
+ - `delete_suffix`, `delete_suffix!`
263
+ - `undump`
209
264
 
210
265
  #### Struct
211
- - `new` (with `keyword_init: true`)
266
+
267
+ - `new` (with `keyword_init: true`)
212
268
 
213
269
  ## Ruby 2.4 backports
214
270
 
215
271
  #### Comparable
216
- - `clamp`
272
+
273
+ - `clamp`
217
274
 
218
275
  #### Enumerable
219
- - `sum`
220
- - `uniq`
276
+
277
+ - `sum`
278
+ - `uniq`
221
279
 
222
280
  #### Hash
223
- - `compact`, `compact!`
224
- - `transform_values`, `transform_values!`
281
+
282
+ - `compact`, `compact!`
283
+ - `transform_values`, `transform_values!`
225
284
 
226
285
  #### Queue
227
- - `close`, `closed?`
286
+
287
+ - `close`, `closed?`
228
288
 
229
289
  #### Regexp
230
- - `match?`
290
+
291
+ - `match?`
231
292
 
232
293
  #### String
233
- - `match?`
294
+
295
+ - `match?`
296
+ - `unpack1`
234
297
 
235
298
  #### FalseClass, Fixnum, Bignum, Float, NilClass, TrueClass
236
- - `dup`
299
+
300
+ - `dup`
237
301
 
238
302
  ## Ruby 2.3 backports
239
303
 
240
304
  #### Array
241
- - `bsearch_index`
242
- - `dig`
305
+
306
+ - `bsearch_index`
307
+ - `dig`
243
308
 
244
309
  #### Enumerable
245
- - `chunk_while`
246
- - `grep_v`
310
+
311
+ - `chunk_while`
312
+ - `grep_v`
247
313
 
248
314
  #### Hash
249
- - `dig`
250
- - `fetch_values`
251
- - `to_proc`
252
- - <=, <, >=, >
315
+
316
+ - `dig`
317
+ - `fetch_values`
318
+ - `to_proc`
319
+ - <=, <, >=, >
253
320
 
254
321
  #### Numeric
255
- - `negative?`
256
- - `positive?`
322
+
323
+ - `negative?`
324
+ - `positive?`
257
325
 
258
326
  #### String
259
- - unary + and -
327
+
328
+ - unary + and -
260
329
 
261
330
  #### Struct
262
- - `dig`
331
+
332
+ - `dig`
263
333
 
264
334
  ## Ruby 2.2 backports
265
335
 
266
336
  #### Enumerable
267
- - `slice_after`
268
- - `slice_when`
337
+
338
+ - `slice_after`
339
+ - `slice_when`
269
340
 
270
341
  #### Float
271
- - `prev_float`
272
- - `next_float`
342
+
343
+ - `prev_float`
344
+ - `next_float`
273
345
 
274
346
  #### Kernel
275
- - `itself`
347
+
348
+ - `itself`
276
349
 
277
350
  #### Method
278
- - `curry`
279
- - `super_method`
351
+
352
+ - `curry`
353
+ - `super_method`
280
354
 
281
355
  #### String
282
- - `unicode_normalize`
283
- - `unicode_normalize!`
284
- - `unicode_normalize?`
356
+
357
+ - `unicode_normalize`
358
+ - `unicode_normalize!`
359
+ - `unicode_normalize?`
285
360
 
286
361
  ## Ruby 2.1 backports
287
362
 
288
363
  #### Array
289
- - `to_h`
364
+
365
+ - `to_h`
290
366
 
291
367
  #### Bignum
292
- - `bit_length`
368
+
369
+ - `bit_length`
293
370
 
294
371
  #### Enumerable
295
- - `to_h`
372
+
373
+ - `to_h`
296
374
 
297
375
  #### Fixnum
298
- - `bit_length`
376
+
377
+ - `bit_length`
299
378
 
300
379
  #### Module
301
- - `include` (now public)
380
+
381
+ - `include` (now public)
382
+ - `singleton_class?`
302
383
 
303
384
  ## Ruby 2.0 backports
304
385
 
305
386
  #### Array
306
- - `bsearch`
387
+
388
+ - `bsearch`
307
389
 
308
390
  #### Enumerable
309
- - `lazy`
391
+
392
+ - `lazy`
310
393
 
311
394
  #### Enumerator::Lazy
312
- - all methods
395
+
396
+ - all methods
313
397
 
314
398
  #### Hash
315
- - `default_proc=` (with nil argument)
316
- - `to_h`
399
+
400
+ - `default_proc=` (with nil argument)
401
+ - `to_h`
317
402
 
318
403
  #### `nil.to_h`
319
404
 
320
405
  #### Range
321
- - `bsearch`
406
+
407
+ - `bsearch`
322
408
 
323
409
  #### Struct
324
- - `to_h`
410
+
411
+ - `to_h`
325
412
 
326
413
  ## Ruby 1.9.3 backports
327
414
 
328
415
  #### File
329
- - `NULL`
416
+
417
+ - `NULL`
330
418
 
331
419
  #### IO
332
- - `advise` (acts as a noop)
333
- - `write`, `binwrite`
420
+
421
+ - `advise` (acts as a noop)
422
+ - `write`, `binwrite`
334
423
 
335
424
  #### String
336
- - `byteslice`
337
- - `prepend`
425
+
426
+ - `byteslice`
427
+ - `prepend`
338
428
 
339
429
  ## Ruby 1.9.2 backports
340
430
 
341
431
  #### Array
342
- - `rotate, rotate!`
343
- - `keep_if, select!`
344
- - `product` (with block)
345
- - `repeated_combination`, `repeated_permutation`
346
- - `sort_by!`
347
- - `uniq, uniq!` (with block)
432
+
433
+ - `rotate, rotate!`
434
+ - `keep_if, select!`
435
+ - `product` (with block)
436
+ - `repeated_combination`, `repeated_permutation`
437
+ - `sort_by!`
438
+ - `uniq, uniq!` (with block)
348
439
 
349
440
  #### Complex
350
- - `to_r`
441
+
442
+ - `to_r`
351
443
 
352
444
  #### Dir
353
- - `home`
445
+
446
+ - `home`
354
447
 
355
448
  #### Enumerable
356
- - `chunk`
357
- - `flat_map`, `collect_concat`
358
- - `join`
359
- - `slice_before`
449
+
450
+ - `chunk`
451
+ - `flat_map`, `collect_concat`
452
+ - `join`
453
+ - `slice_before`
360
454
 
361
455
  #### Float::INFINITY, NAN
362
456
 
363
457
  #### Hash
364
- - `keep_if`, `select!`
458
+
459
+ - `keep_if`, `select!`
365
460
 
366
461
  #### Object
367
- - `singleton_class`
462
+
463
+ - `singleton_class`
368
464
 
369
465
  #### Random (new class)
370
466
 
371
- *Note*: The methods of `Random` can't be required individually; the class
467
+ _Note_: The methods of `Random` can't be required individually; the class
372
468
  can only be required whole with `require 'backports/1.9.2/random'`.
373
469
 
374
470
  ## Ruby 1.9.1 backports
375
471
 
376
472
  Additionally, the following Ruby 1.9 features have been backported:
473
+
377
474
  #### Array
378
- - `try_convert`
379
- - `sample`
475
+
476
+ - `try_convert`
477
+ - `sample`
380
478
 
381
479
  #### Enumerable
382
- - `each_with_object`
383
- - `each_with_index` (with arguments)
480
+
481
+ - `each_with_object`
482
+ - `each_with_index` (with arguments)
384
483
 
385
484
  #### Enumerator
386
- - `new` (with block)
485
+
486
+ - `new` (with block)
387
487
 
388
488
  #### File
389
- - `binread`
390
- - `to_path`
391
- - All class methods accepting filenames will accept files or anything
392
- with a `#to_path` method.
393
- - `File.open` accepts an options hash.
489
+
490
+ - `binread`
491
+ - `to_path`
492
+ - All class methods accepting filenames will accept files or anything
493
+ with a `#to_path` method.
494
+ - `File.open` accepts an options hash.
394
495
 
395
496
  #### Float
396
- - `round`
497
+
498
+ - `round`
397
499
 
398
500
  #### Hash
399
- - `assoc`, `rassoc`
400
- - `key`
401
- - `try_convert`
402
- - `default_proc=`
501
+
502
+ - `assoc`, `rassoc`
503
+ - `key`
504
+ - `try_convert`
505
+ - `default_proc=`
403
506
 
404
507
  #### Integer
405
- - `magnitude`
406
- - `round`
508
+
509
+ - `magnitude`
510
+ - `round`
407
511
 
408
512
  #### IO
409
- - `bin_read`
410
- - `try_convert`
411
- - `ungetbyte`
412
- - `IO.open` accepts an options hash.
513
+
514
+ - `bin_read`
515
+ - `try_convert`
516
+ - `ungetbyte`
517
+ - `IO.open` accepts an options hash.
413
518
 
414
519
  #### Kernel
415
- - `require_relative`
520
+
521
+ - `require_relative`
416
522
 
417
523
  #### Math
418
- - `log` (with base)
419
- - `log2`
524
+
525
+ - `log` (with base)
526
+ - `log2`
420
527
 
421
528
  #### Numeric
422
- - `round`
529
+
530
+ - `round`
423
531
 
424
532
  #### Object
425
- - `define_singleton_method`
426
- - `public_method`
427
- - `public_send`
533
+
534
+ - `define_singleton_method`
535
+ - `public_method`
536
+ - `public_send`
428
537
 
429
538
  #### Proc
430
- - `yield`
431
- - `lambda?`
432
- - `curry`
433
- - `===`
539
+
540
+ - `yield`
541
+ - `lambda?`
542
+ - `curry`
543
+ - `===`
434
544
 
435
545
  #### Range
436
- - `cover?`
546
+
547
+ - `cover?`
437
548
 
438
549
  #### Regexp
439
- - `try_convert`
550
+
551
+ - `try_convert`
440
552
 
441
553
  #### String
442
- - `ascii_only?`
443
- - `chr`
444
- - `clear`
445
- - `codepoints`, `each_codepoint`
446
- - `get_byte`, `set_byte`
447
- - `ord`
448
- - `try_convert`
554
+
555
+ - `ascii_only?`
556
+ - `chr`
557
+ - `clear`
558
+ - `codepoints`, `each_codepoint`
559
+ - `get_byte`, `set_byte`
560
+ - `ord`
561
+ - `try_convert`
449
562
 
450
563
  `Enumerator` can be accessed directly (instead of `Enumerable::Enumerator`)
451
564
 
452
- To include *only* these backports and those of the 1.8 line, `require
453
- "backports/1.9.1"`.
565
+ To include _only_ these backports and those of the 1.8 line, `require "backports/1.9.1"`.
454
566
 
455
567
  Moreover, a pretty good imitation of `BasicObject` is available, but since it
456
568
  is only an imitation, it must be required explicitly:
@@ -464,8 +576,11 @@ Complete Ruby 1.8.7 backporting (core language). Refer to the official list of
464
576
  backports!
465
577
 
466
578
  Only exceptions:
579
+
467
580
  #### String#gsub (the form returning an enumerator)
468
- #### GC.stress= (not implemented)
581
+
582
+ #### GC.stress= (not implemented)
583
+
469
584
  #### Array#choice (removed in 1.9, use 1.9.1's Array#sample instead)
470
585
 
471
586
  ## Libraries
@@ -477,7 +592,9 @@ The backports would be automatically used after requiring 'backports/std_lib' bu
477
592
  The following libraries are up to date with Ruby 1.9.3:
478
593
 
479
594
  #### Matrix
595
+
480
596
  #### Prime
597
+
481
598
  #### Set
482
599
 
483
600
  The following library is to date with Ruby 2.0.0:
@@ -488,6 +605,7 @@ I am aware of the following backport gem, which probably won't make it into
488
605
  this gem:
489
606
 
490
607
  #### Net::SMTP for Ruby 1.8.6:
608
+
491
609
  [smtp_tls](http://seattlerb.rubyforge.org/smtp_tls/)
492
610
 
493
611
  Requiring backports for a given version of Ruby will also load
@@ -500,13 +618,16 @@ but could be useful in some projects. It is possible to request such
500
618
  incompatible changes. Backports currently supports the following:
501
619
 
502
620
  #### Hash
503
- - `select` (returns a Hash instead of an Array)
621
+
622
+ - `select` (returns a Hash instead of an Array)
504
623
 
505
624
  #### Enumerable / Array
506
- - `map` (returns an enumerator when called without a block)
625
+
626
+ - `map` (returns an enumerator when called without a block)
507
627
 
508
628
  #### String
509
- - `length`, `size` (for UTF-8 support)
629
+
630
+ - `length`, `size` (for UTF-8 support)
510
631
 
511
632
  These must be imported in addition to the backports gem, for example:
512
633
 
@@ -518,8 +639,11 @@ These must be imported in addition to the backports gem, for example:
518
639
  Thanks for the bug reports and patches, in particular the repeat offenders:
519
640
 
520
641
  #### Arto Bendiken ( [bendiken](http://github.com/bendiken) )
642
+
521
643
  #### Konstantin Haase ( [rkh](https://github.com/rkh) )
644
+
522
645
  #### Roger Pack ( [rdp](http://github.com/rdp) )
646
+
523
647
  #### Victor Shepelev ( [zverok](http://github.com/zverok) )
524
648
 
525
649
  ## Contributing
@@ -545,5 +669,4 @@ Failures that are acceptable are added the to `tags` file.
545
669
  LICENSE file.
546
670
 
547
671
  Author
548
- : Marc-André Lafortune
549
-
672
+ : Marc-André Lafortune