backports 3.24.1 → 3.25.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +15 -8
- data/lib/backports/3.1.0.rb +1 -1
- data/lib/backports/3.2.0/enumerator/product.rb +46 -6
- data/lib/backports/3.2.0.rb +1 -1
- data/lib/backports/3.3.0/match_data/named_captures.rb +12 -0
- data/lib/backports/3.3.0/match_data.rb +3 -0
- data/lib/backports/3.3.0/range/overlap.rb +18 -0
- data/lib/backports/3.3.0/range/reverse_each.rb +20 -0
- data/lib/backports/3.3.0/range.rb +3 -0
- data/lib/backports/3.3.0.rb +3 -0
- data/lib/backports/3.3.rb +1 -0
- data/lib/backports/version.rb +1 -1
- metadata +13 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36ede0c424a25b64633c443a48c716c2876ac448c5a34544c842f5a5710ff03c
|
4
|
+
data.tar.gz: c8d3d198e817f6dc9d37f21519d84e1252e53482969a6759e25774a16fec93e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5a36ace358abdf8dbce16371ee1f49c07d23373e537322f8079578e283d5e095ac06261b572b3574e88543148e4c1f5127204aecbfdbd817d7dcdef72574fcf
|
7
|
+
data.tar.gz: abe5101c680b15fe50d6743f7d5b702a3726a4b5c0b13c4e4d2474aa6f1d6f693557fcd74dad46a3b2b050628094fe668b23d73f7f005e74d99734891c8a5ee9
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
|
5
5
|
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## [3.25.0](https://github.com/marcandre/backports/compare/v3.24.0...v3.25.0) - 2024-03-05
|
8
|
+
|
9
|
+
## Added
|
10
|
+
|
11
|
+
- `MatchData#named_captures` (with `symbolize_keys` option, Ruby 3.3)
|
12
|
+
- `Range.reverse_each` (Ruby 3.3)
|
13
|
+
- `Range#overlap?` (Ruby 3.3)
|
14
|
+
|
7
15
|
## [3.24.0](https://github.com/marcandre/backports/compare/v3.23.0...v3.24.0) - 2023-03-07
|
8
16
|
|
9
17
|
## Added
|
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) [](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.
|
3
|
+
Yearning to write a gem using some new cool features in Ruby 3.3 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
|
|
@@ -9,10 +9,6 @@ This gem is for you!
|
|
9
9
|
The goal of 'backports' is to make it easier to write ruby code that runs
|
10
10
|
across different versions of Ruby.
|
11
11
|
|
12
|
-
Note: [Next major version (X-mas
|
13
|
-
2021?)](https://github.com/marcandre/backports/issues/139) may drop support
|
14
|
-
for Ruby < 2.2.
|
15
|
-
|
16
12
|
## Loading backports
|
17
13
|
|
18
14
|
### Explicitly (recommended)
|
@@ -38,12 +34,12 @@ This will make sure that Hash responds to `dig`, `fetch_values`, `to_proc` and c
|
|
38
34
|
### Up to a specific Ruby version (for quick coding)
|
39
35
|
|
40
36
|
You can load all backports up to a specific version.
|
41
|
-
For example, to bring any version of Ruby mostly up to Ruby 3.
|
37
|
+
For example, to bring any version of Ruby mostly up to Ruby 3.3.0's standards:
|
42
38
|
|
43
|
-
require 'backports/3.
|
39
|
+
require 'backports/3.3.0'
|
44
40
|
|
45
41
|
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.
|
42
|
+
all the way up to Ruby 3.3.0 (for all versions of Ruby)!
|
47
43
|
|
48
44
|
You may `require 'backports/latest'` as a
|
49
45
|
shortcut to the latest Ruby version supported.
|
@@ -109,6 +105,17 @@ itself, JRuby and Rubinius.
|
|
109
105
|
|
110
106
|
# Complete List of backports
|
111
107
|
|
108
|
+
## Ruby 3.3 backports
|
109
|
+
|
110
|
+
#### MatchData
|
111
|
+
|
112
|
+
- `named_captures` (with `symbolize_keys` option)
|
113
|
+
|
114
|
+
#### Range
|
115
|
+
|
116
|
+
- `reverse_each` (with correct handling of endless Ranges)
|
117
|
+
- `overlap?`
|
118
|
+
|
112
119
|
## Ruby 3.2 backports
|
113
120
|
|
114
121
|
#### Class
|
data/lib/backports/3.1.0.rb
CHANGED
@@ -1,13 +1,34 @@
|
|
1
1
|
unless Enumerator.method_defined? :product
|
2
2
|
if RUBY_VERSION >= '2.7'
|
3
|
-
instance_eval <<-EOT, __FILE__, __LINE__ + 1
|
4
|
-
def Enumerator.product(*enums, **
|
5
|
-
|
3
|
+
instance_eval <<-'EOT', __FILE__, __LINE__ + 1
|
4
|
+
def Enumerator.product(*enums, **kwargs, &block)
|
5
|
+
if kwargs && !kwargs.empty?
|
6
|
+
raise ArgumentError, "unknown keywords: #{kwargs.keys.map(&:inspect).join(', ')}"
|
7
|
+
end
|
8
|
+
product = Enumerator::Product.new(*enums)
|
9
|
+
|
10
|
+
if block_given?
|
11
|
+
product.each(&block)
|
12
|
+
return nil
|
13
|
+
end
|
14
|
+
|
15
|
+
product
|
6
16
|
end
|
7
17
|
EOT
|
8
18
|
else
|
9
19
|
def Enumerator.product(*enums, &block)
|
10
|
-
|
20
|
+
kwargs = enums[-1]
|
21
|
+
if kwargs.is_a?(Hash) && !kwargs.empty?
|
22
|
+
raise ArgumentError, "unknown keywords: #{kwargs.keys.map(&:inspect).join(', ')}"
|
23
|
+
end
|
24
|
+
product = Enumerator::Product.new(*enums)
|
25
|
+
|
26
|
+
if block_given?
|
27
|
+
product.each(&block)
|
28
|
+
return nil
|
29
|
+
end
|
30
|
+
|
31
|
+
product
|
11
32
|
end
|
12
33
|
end
|
13
34
|
|
@@ -29,6 +50,7 @@ unless Enumerator.method_defined? :product
|
|
29
50
|
def each(&block)
|
30
51
|
return self unless block
|
31
52
|
__execute(block, [], @__enums)
|
53
|
+
self
|
32
54
|
end
|
33
55
|
|
34
56
|
def __execute(block, values, enums)
|
@@ -47,18 +69,36 @@ unless Enumerator.method_defined? :product
|
|
47
69
|
def size
|
48
70
|
total_size = 1
|
49
71
|
@__enums.each do |enum|
|
72
|
+
return nil unless enum.respond_to?(:size)
|
50
73
|
size = enum.size
|
51
|
-
return size if size == nil || size == Float::INFINITY
|
74
|
+
return size if size == 0 || size == nil || size == Float::INFINITY || size == -Float::INFINITY
|
75
|
+
return nil unless size.is_a?(Integer)
|
52
76
|
total_size *= size
|
53
77
|
end
|
54
78
|
total_size
|
55
79
|
end
|
56
80
|
|
57
81
|
def rewind
|
58
|
-
@__enums.
|
82
|
+
@__enums.each do |enum|
|
59
83
|
enum.rewind if enum.respond_to?(:rewind)
|
60
84
|
end
|
61
85
|
self
|
62
86
|
end
|
87
|
+
|
88
|
+
private def initialize_copy(other)
|
89
|
+
return self if equal?(other)
|
90
|
+
|
91
|
+
raise TypeError unless Product === other
|
92
|
+
|
93
|
+
super(other)
|
94
|
+
|
95
|
+
other_enums = other.instance_variable_get(:@__enums)
|
96
|
+
|
97
|
+
raise ArgumentError, "uninitialized product" unless other_enums
|
98
|
+
|
99
|
+
@__enums = other_enums
|
100
|
+
|
101
|
+
self
|
102
|
+
end
|
63
103
|
end
|
64
104
|
end
|
data/lib/backports/3.2.0.rb
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
if (MatchData.instance_method(:named_captures).arity == 0 rescue false)
|
2
|
+
require 'backports/tools/alias_method_chain'
|
3
|
+
|
4
|
+
class MatchData
|
5
|
+
def named_captures_with_symbolize_option(symbolize_keys: false)
|
6
|
+
captures = named_captures_without_symbolize_option
|
7
|
+
captures.transform_keys!(&:to_sym) if symbolize_keys
|
8
|
+
captures
|
9
|
+
end
|
10
|
+
Backports.alias_method_chain self, :named_captures, :symbolize_option
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
unless Range.method_defined? :overlap?
|
2
|
+
class Range
|
3
|
+
def overlap?(other)
|
4
|
+
raise TypeError, "wrong argument type #{other.class} (expected Range)" unless other.is_a?(Range)
|
5
|
+
|
6
|
+
[
|
7
|
+
[other.begin, self.end, exclude_end?],
|
8
|
+
[self.begin, other.end, other.exclude_end?],
|
9
|
+
[self.begin, self.end, exclude_end?],
|
10
|
+
[other.begin, other.end, other.exclude_end?],
|
11
|
+
].all? do |from, to, excl|
|
12
|
+
less = (from || -Float::INFINITY) <=> (to || Float::INFINITY)
|
13
|
+
less = +1 if less == 0 && excl
|
14
|
+
less && less <= 0
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
unless (Range.new(nil, 3) rescue [:ok]).reverse_each.first
|
2
|
+
require 'backports/tools/alias_method_chain'
|
3
|
+
|
4
|
+
class Range
|
5
|
+
def reverse_each_with_endless_handling(&block)
|
6
|
+
case self.end
|
7
|
+
when nil
|
8
|
+
raise "Hey"
|
9
|
+
when Float::INFINITY
|
10
|
+
raise "Hey"
|
11
|
+
when Integer
|
12
|
+
delta = exclusive? ? 1 : 0
|
13
|
+
((self.end - delta)..(self.begin)).each(&block)
|
14
|
+
else
|
15
|
+
reverse_each_without_endless_handling(&block)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
Backports.alias_method_chain self, :reverse_each, :endless_handling
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'backports/3.3.0'
|
data/lib/backports/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Backports
|
2
|
-
VERSION = "3.
|
2
|
+
VERSION = "3.25.1" 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.
|
4
|
+
version: 3.25.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marc-André Lafortune
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-03-20 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.
|
@@ -577,6 +577,13 @@ files:
|
|
577
577
|
- lib/backports/3.2.0/match_data.rb
|
578
578
|
- lib/backports/3.2.0/match_data/byteoffset.rb
|
579
579
|
- lib/backports/3.2.rb
|
580
|
+
- lib/backports/3.3.0.rb
|
581
|
+
- lib/backports/3.3.0/match_data.rb
|
582
|
+
- lib/backports/3.3.0/match_data/named_captures.rb
|
583
|
+
- lib/backports/3.3.0/range.rb
|
584
|
+
- lib/backports/3.3.0/range/overlap.rb
|
585
|
+
- lib/backports/3.3.0/range/reverse_each.rb
|
586
|
+
- lib/backports/3.3.rb
|
580
587
|
- lib/backports/basic_object.rb
|
581
588
|
- lib/backports/force/array_map.rb
|
582
589
|
- lib/backports/force/enumerable_map.rb
|
@@ -624,7 +631,7 @@ metadata:
|
|
624
631
|
changelog_uri: https://github.com/marcandre/backports/blob/master/CHANGELOG.md
|
625
632
|
source_code_uri: https://github.com/marcandre/backports
|
626
633
|
bug_tracker_uri: https://github.com/marcandre/backports/issues
|
627
|
-
post_install_message:
|
634
|
+
post_install_message:
|
628
635
|
rdoc_options: []
|
629
636
|
require_paths:
|
630
637
|
- lib
|
@@ -639,8 +646,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
639
646
|
- !ruby/object:Gem::Version
|
640
647
|
version: '0'
|
641
648
|
requirements: []
|
642
|
-
rubygems_version: 3.
|
643
|
-
signing_key:
|
649
|
+
rubygems_version: 3.5.11
|
650
|
+
signing_key:
|
644
651
|
specification_version: 4
|
645
652
|
summary: Backports of Ruby features for older Ruby.
|
646
653
|
test_files: []
|