backports 3.24.1 → 3.25.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: e2a822b77667d9e87ca05ecb722dc91204f4ef72e88575b534d969bd0c2784f1
4
- data.tar.gz: 47bb61fa96fde1da093d230fd7fab4f45dfbe58bf89ac1db56dceb9d0525a7e0
3
+ metadata.gz: d32b8fd798a8e0818db2558a2c55dbd2ca32640f9f398a20a9c6f6262b5eebfc
4
+ data.tar.gz: 5a2a941edd216415a39d36c1c7381f2e1cb6a95048959ad47927d227847db21c
5
5
  SHA512:
6
- metadata.gz: 45939ddca1b04d95d536e652780205d8e53fd154705ce0d28fa79abcaedd628375e81abe5972638edf3d57cdf874426c8b8756156a4f6691c1682843dbdf0ad1
7
- data.tar.gz: 9e0f10a128b5871c015beb2c77838599f0877213a998d983fe18433b8b09df48e974e15dd9b97fb0a11af873c367e2908558bd48fe9184627a48ab5c79ffaed5
6
+ metadata.gz: ece306aa682890039f68416f34e0e874e6285f31c5de18e888dd19239e0038cce94ab9767d0b6efa86dfb0aa910e29c3e4e7d7f30dcabd200901309c1c521b72
7
+ data.tar.gz: f4de8e83504012fdcb51ee5fc9a49e2ec2e3a9b16578d1f8f920afd830801c555651d016f566e74697f242127b9b9f3e3906410cde3269cf6d419702ee07e342
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) [![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.2 while
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.2.0's standards:
37
+ For example, to bring any version of Ruby mostly up to Ruby 3.3.0's standards:
42
38
 
43
- require 'backports/3.2.0'
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.2.0 (for all versions of Ruby)!
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
@@ -1,3 +1,3 @@
1
- # require this file to load all the backports up to Ruby 3.0
1
+ # require this file to load all the backports up to Ruby 3.1
2
2
  require 'backports/3.0.0'
3
3
  Backports.require_relative_dir if RUBY_VERSION < '3.1'
@@ -1,12 +1,19 @@
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, **nil, &block)
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
5
8
  Enumerator::Product.new(*enums).each(&block)
6
9
  end
7
10
  EOT
8
11
  else
9
12
  def Enumerator.product(*enums, &block)
13
+ kwargs = enums[-1]
14
+ if kwargs.is_a?(Hash) && !kwargs.empty?
15
+ raise ArgumentError, "unknown keywords: #{kwargs.keys.map(&:inspect).join(', ')}"
16
+ end
10
17
  Enumerator::Product.new(*enums).each(&block)
11
18
  end
12
19
  end
@@ -47,15 +54,17 @@ unless Enumerator.method_defined? :product
47
54
  def size
48
55
  total_size = 1
49
56
  @__enums.each do |enum|
57
+ return nil unless enum.respond_to?(:size)
50
58
  size = enum.size
51
- return size if size == nil || size == Float::INFINITY
59
+ return size if size == nil || size == Float::INFINITY || size == 0
60
+ return nil unless size.is_a?(Integer)
52
61
  total_size *= size
53
62
  end
54
63
  total_size
55
64
  end
56
65
 
57
66
  def rewind
58
- @__enums.reverse_each do |enum|
67
+ @__enums.each do |enum|
59
68
  enum.rewind if enum.respond_to?(:rewind)
60
69
  end
61
70
  self
@@ -1,3 +1,3 @@
1
- # require this file to load all the backports up to Ruby 3.0
1
+ # require this file to load all the backports up to Ruby 3.2
2
2
  require 'backports/3.1.0'
3
3
  Backports.require_relative_dir if RUBY_VERSION < '3.2'
@@ -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,3 @@
1
+ require 'backports/tools/require_relative_dir'
2
+
3
+ Backports.require_relative_dir
@@ -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,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.3
2
+ require 'backports/3.2.0'
3
+ Backports.require_relative_dir if RUBY_VERSION < '3.3'
@@ -0,0 +1 @@
1
+ require 'backports/3.3.0'
@@ -1,3 +1,3 @@
1
1
  module Backports
2
- VERSION = "3.24.1" unless Backports.constants.include? :VERSION # the guard is against a redefinition warning that happens on Travis
2
+ VERSION = "3.25.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.24.1
4
+ version: 3.25.0
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: 2023-04-05 00:00:00.000000000 Z
11
+ date: 2024-03-05 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.1.6
643
- signing_key:
649
+ rubygems_version: 3.4.10
650
+ signing_key:
644
651
  specification_version: 4
645
652
  summary: Backports of Ruby features for older Ruby.
646
653
  test_files: []