backports 3.20.0 → 3.22.0

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 (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/Gemfile +1 -1
  4. data/README.md +285 -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/integer/try_convert.rb +5 -0
  25. data/lib/backports/3.1.0/integer.rb +3 -0
  26. data/lib/backports/3.1.0/match_data/match.rb +5 -0
  27. data/lib/backports/3.1.0/match_data/match_length.rb +6 -0
  28. data/lib/backports/3.1.0/match_data.rb +3 -0
  29. data/lib/backports/3.1.0/struct/keyword_init.rb +5 -0
  30. data/lib/backports/3.1.0/struct.rb +3 -0
  31. data/lib/backports/3.1.0.rb +3 -0
  32. data/lib/backports/3.1.rb +1 -0
  33. data/lib/backports/latest.rb +1 -1
  34. data/lib/backports/ractor/cloner.rb +81 -69
  35. data/lib/backports/ractor/errors.rb +14 -10
  36. data/lib/backports/{tools → ractor}/filtered_queue.rb +11 -8
  37. data/lib/backports/ractor/queues.rb +50 -46
  38. data/lib/backports/ractor/ractor.rb +225 -191
  39. data/lib/backports/ractor/sharing.rb +75 -71
  40. data/lib/backports/version.rb +1 -1
  41. metadata +25 -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,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?`
298
+
299
+ - `match?`
300
+ - `unpack1`
234
301
 
235
302
  #### FalseClass, Fixnum, Bignum, Float, NilClass, TrueClass
236
- - `dup`
303
+
304
+ - `dup`
237
305
 
238
306
  ## Ruby 2.3 backports
239
307
 
240
308
  #### Array
241
- - `bsearch_index`
242
- - `dig`
309
+
310
+ - `bsearch_index`
311
+ - `dig`
243
312
 
244
313
  #### Enumerable
245
- - `chunk_while`
246
- - `grep_v`
314
+
315
+ - `chunk_while`
316
+ - `grep_v`
247
317
 
248
318
  #### Hash
249
- - `dig`
250
- - `fetch_values`
251
- - `to_proc`
252
- - <=, <, >=, >
319
+
320
+ - `dig`
321
+ - `fetch_values`
322
+ - `to_proc`
323
+ - <=, <, >=, >
253
324
 
254
325
  #### Numeric
255
- - `negative?`
256
- - `positive?`
326
+
327
+ - `negative?`
328
+ - `positive?`
257
329
 
258
330
  #### String
259
- - unary + and -
331
+
332
+ - unary + and -
260
333
 
261
334
  #### Struct
262
- - `dig`
335
+
336
+ - `dig`
263
337
 
264
338
  ## Ruby 2.2 backports
265
339
 
266
340
  #### Enumerable
267
- - `slice_after`
268
- - `slice_when`
341
+
342
+ - `slice_after`
343
+ - `slice_when`
269
344
 
270
345
  #### Float
271
- - `prev_float`
272
- - `next_float`
346
+
347
+ - `prev_float`
348
+ - `next_float`
273
349
 
274
350
  #### Kernel
275
- - `itself`
351
+
352
+ - `itself`
276
353
 
277
354
  #### Method
278
- - `curry`
279
- - `super_method`
355
+
356
+ - `curry`
357
+ - `super_method`
280
358
 
281
359
  #### String
282
- - `unicode_normalize`
283
- - `unicode_normalize!`
284
- - `unicode_normalize?`
360
+
361
+ - `unicode_normalize`
362
+ - `unicode_normalize!`
363
+ - `unicode_normalize?`
285
364
 
286
365
  ## Ruby 2.1 backports
287
366
 
288
367
  #### Array
289
- - `to_h`
368
+
369
+ - `to_h`
290
370
 
291
371
  #### Bignum
292
- - `bit_length`
372
+
373
+ - `bit_length`
293
374
 
294
375
  #### Enumerable
295
- - `to_h`
376
+
377
+ - `to_h`
296
378
 
297
379
  #### Fixnum
298
- - `bit_length`
380
+
381
+ - `bit_length`
299
382
 
300
383
  #### Module
301
- - `include` (now public)
384
+
385
+ - `include` (now public)
386
+ - `singleton_class?`
302
387
 
303
388
  ## Ruby 2.0 backports
304
389
 
305
390
  #### Array
306
- - `bsearch`
391
+
392
+ - `bsearch`
307
393
 
308
394
  #### Enumerable
309
- - `lazy`
395
+
396
+ - `lazy`
310
397
 
311
398
  #### Enumerator::Lazy
312
- - all methods
399
+
400
+ - all methods
313
401
 
314
402
  #### Hash
315
- - `default_proc=` (with nil argument)
316
- - `to_h`
403
+
404
+ - `default_proc=` (with nil argument)
405
+ - `to_h`
317
406
 
318
407
  #### `nil.to_h`
319
408
 
320
409
  #### Range
321
- - `bsearch`
410
+
411
+ - `bsearch`
322
412
 
323
413
  #### Struct
324
- - `to_h`
414
+
415
+ - `to_h`
325
416
 
326
417
  ## Ruby 1.9.3 backports
327
418
 
328
419
  #### File
329
- - `NULL`
420
+
421
+ - `NULL`
330
422
 
331
423
  #### IO
332
- - `advise` (acts as a noop)
333
- - `write`, `binwrite`
424
+
425
+ - `advise` (acts as a noop)
426
+ - `write`, `binwrite`
334
427
 
335
428
  #### String
336
- - `byteslice`
337
- - `prepend`
429
+
430
+ - `byteslice`
431
+ - `prepend`
338
432
 
339
433
  ## Ruby 1.9.2 backports
340
434
 
341
435
  #### 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)
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)
348
443
 
349
444
  #### Complex
350
- - `to_r`
445
+
446
+ - `to_r`
351
447
 
352
448
  #### Dir
353
- - `home`
449
+
450
+ - `home`
354
451
 
355
452
  #### Enumerable
356
- - `chunk`
357
- - `flat_map`, `collect_concat`
358
- - `join`
359
- - `slice_before`
453
+
454
+ - `chunk`
455
+ - `flat_map`, `collect_concat`
456
+ - `join`
457
+ - `slice_before`
360
458
 
361
459
  #### Float::INFINITY, NAN
362
460
 
363
461
  #### Hash
364
- - `keep_if`, `select!`
462
+
463
+ - `keep_if`, `select!`
365
464
 
366
465
  #### Object
367
- - `singleton_class`
466
+
467
+ - `singleton_class`
368
468
 
369
469
  #### Random (new class)
370
470
 
371
- *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
372
472
  can only be required whole with `require 'backports/1.9.2/random'`.
373
473
 
374
474
  ## Ruby 1.9.1 backports
375
475
 
376
476
  Additionally, the following Ruby 1.9 features have been backported:
477
+
377
478
  #### Array
378
- - `try_convert`
379
- - `sample`
479
+
480
+ - `try_convert`
481
+ - `sample`
380
482
 
381
483
  #### Enumerable
382
- - `each_with_object`
383
- - `each_with_index` (with arguments)
484
+
485
+ - `each_with_object`
486
+ - `each_with_index` (with arguments)
384
487
 
385
488
  #### Enumerator
386
- - `new` (with block)
489
+
490
+ - `new` (with block)
387
491
 
388
492
  #### 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.
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.
394
499
 
395
500
  #### Float
396
- - `round`
501
+
502
+ - `round`
397
503
 
398
504
  #### Hash
399
- - `assoc`, `rassoc`
400
- - `key`
401
- - `try_convert`
402
- - `default_proc=`
505
+
506
+ - `assoc`, `rassoc`
507
+ - `key`
508
+ - `try_convert`
509
+ - `default_proc=`
403
510
 
404
511
  #### Integer
405
- - `magnitude`
406
- - `round`
512
+
513
+ - `magnitude`
514
+ - `round`
407
515
 
408
516
  #### IO
409
- - `bin_read`
410
- - `try_convert`
411
- - `ungetbyte`
412
- - `IO.open` accepts an options hash.
517
+
518
+ - `bin_read`
519
+ - `try_convert`
520
+ - `ungetbyte`
521
+ - `IO.open` accepts an options hash.
413
522
 
414
523
  #### Kernel
415
- - `require_relative`
524
+
525
+ - `require_relative`
416
526
 
417
527
  #### Math
418
- - `log` (with base)
419
- - `log2`
528
+
529
+ - `log` (with base)
530
+ - `log2`
420
531
 
421
532
  #### Numeric
422
- - `round`
533
+
534
+ - `round`
423
535
 
424
536
  #### Object
425
- - `define_singleton_method`
426
- - `public_method`
427
- - `public_send`
537
+
538
+ - `define_singleton_method`
539
+ - `public_method`
540
+ - `public_send`
428
541
 
429
542
  #### Proc
430
- - `yield`
431
- - `lambda?`
432
- - `curry`
433
- - `===`
543
+
544
+ - `yield`
545
+ - `lambda?`
546
+ - `curry`
547
+ - `===`
434
548
 
435
549
  #### Range
436
- - `cover?`
550
+
551
+ - `cover?`
437
552
 
438
553
  #### Regexp
439
- - `try_convert`
554
+
555
+ - `try_convert`
440
556
 
441
557
  #### String
442
- - `ascii_only?`
443
- - `chr`
444
- - `clear`
445
- - `codepoints`, `each_codepoint`
446
- - `get_byte`, `set_byte`
447
- - `ord`
448
- - `try_convert`
558
+
559
+ - `ascii_only?`
560
+ - `chr`
561
+ - `clear`
562
+ - `codepoints`, `each_codepoint`
563
+ - `get_byte`, `set_byte`
564
+ - `ord`
565
+ - `try_convert`
449
566
 
450
567
  `Enumerator` can be accessed directly (instead of `Enumerable::Enumerator`)
451
568
 
452
- To include *only* these backports and those of the 1.8 line, `require
453
- "backports/1.9.1"`.
569
+ To include _only_ these backports and those of the 1.8 line, `require "backports/1.9.1"`.
454
570
 
455
571
  Moreover, a pretty good imitation of `BasicObject` is available, but since it
456
572
  is only an imitation, it must be required explicitly:
@@ -464,8 +580,11 @@ Complete Ruby 1.8.7 backporting (core language). Refer to the official list of
464
580
  backports!
465
581
 
466
582
  Only exceptions:
583
+
467
584
  #### String#gsub (the form returning an enumerator)
468
- #### GC.stress= (not implemented)
585
+
586
+ #### GC.stress= (not implemented)
587
+
469
588
  #### Array#choice (removed in 1.9, use 1.9.1's Array#sample instead)
470
589
 
471
590
  ## Libraries
@@ -477,7 +596,9 @@ The backports would be automatically used after requiring 'backports/std_lib' bu
477
596
  The following libraries are up to date with Ruby 1.9.3:
478
597
 
479
598
  #### Matrix
599
+
480
600
  #### Prime
601
+
481
602
  #### Set
482
603
 
483
604
  The following library is to date with Ruby 2.0.0:
@@ -488,6 +609,7 @@ I am aware of the following backport gem, which probably won't make it into
488
609
  this gem:
489
610
 
490
611
  #### Net::SMTP for Ruby 1.8.6:
612
+
491
613
  [smtp_tls](http://seattlerb.rubyforge.org/smtp_tls/)
492
614
 
493
615
  Requiring backports for a given version of Ruby will also load
@@ -500,13 +622,16 @@ but could be useful in some projects. It is possible to request such
500
622
  incompatible changes. Backports currently supports the following:
501
623
 
502
624
  #### Hash
503
- - `select` (returns a Hash instead of an Array)
625
+
626
+ - `select` (returns a Hash instead of an Array)
504
627
 
505
628
  #### Enumerable / Array
506
- - `map` (returns an enumerator when called without a block)
629
+
630
+ - `map` (returns an enumerator when called without a block)
507
631
 
508
632
  #### String
509
- - `length`, `size` (for UTF-8 support)
633
+
634
+ - `length`, `size` (for UTF-8 support)
510
635
 
511
636
  These must be imported in addition to the backports gem, for example:
512
637
 
@@ -518,8 +643,11 @@ These must be imported in addition to the backports gem, for example:
518
643
  Thanks for the bug reports and patches, in particular the repeat offenders:
519
644
 
520
645
  #### Arto Bendiken ( [bendiken](http://github.com/bendiken) )
646
+
521
647
  #### Konstantin Haase ( [rkh](https://github.com/rkh) )
648
+
522
649
  #### Roger Pack ( [rdp](http://github.com/rdp) )
650
+
523
651
  #### Victor Shepelev ( [zverok](http://github.com/zverok) )
524
652
 
525
653
  ## Contributing
@@ -545,5 +673,4 @@ Failures that are acceptable are added the to `tags` file.
545
673
  LICENSE file.
546
674
 
547
675
  Author
548
- : Marc-André Lafortune
549
-
676
+ : Marc-André Lafortune