backports 3.18.0 → 3.23.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +435 -292
  3. data/Gemfile +3 -16
  4. data/README.md +306 -156
  5. data/backports.gemspec +1 -1
  6. data/lib/backports/2.0.0.rb +1 -1
  7. data/lib/backports/2.1.0/module/singleton_class.rb +8 -0
  8. data/lib/backports/2.1.0.rb +1 -1
  9. data/lib/backports/2.2.0/string/unicode_normalize.rb +3 -3
  10. data/lib/backports/2.2.0.rb +1 -1
  11. data/lib/backports/2.3.0/queue/close.rb +48 -0
  12. data/lib/backports/2.3.0/string.rb +3 -0
  13. data/lib/backports/2.3.0/struct/dig.rb +2 -0
  14. data/lib/backports/2.3.0.rb +1 -1
  15. data/lib/backports/2.4.0/bignum/dup.rb +5 -0
  16. data/lib/backports/2.4.0/bignum.rb +3 -0
  17. data/lib/backports/2.4.0/string/unpack1.rb +7 -0
  18. data/lib/backports/2.4.0.rb +1 -1
  19. data/lib/backports/2.5.0/dir/children.rb +4 -0
  20. data/lib/backports/2.5.0/dir/each_child.rb +7 -0
  21. data/lib/backports/2.5.0/hash/transform_keys.rb +10 -3
  22. data/lib/backports/2.5.0/string/undump.rb +2 -2
  23. data/lib/backports/2.5.0.rb +1 -1
  24. data/lib/backports/2.5.rb +1 -1
  25. data/lib/backports/2.6.0/enumerable/chain.rb +2 -0
  26. data/lib/backports/2.6.0.rb +2 -2
  27. data/lib/backports/2.6.rb +1 -1
  28. data/lib/backports/2.7.0/complex/{comparision.rb → comparison.rb} +0 -0
  29. data/lib/backports/2.7.0/enumerable/tally.rb +4 -3
  30. data/lib/backports/2.7.0/symbol/end_with.rb +9 -0
  31. data/lib/backports/2.7.0/symbol.rb +3 -0
  32. data/lib/backports/2.7.0.rb +2 -2
  33. data/lib/backports/3.0.0/env/except.rb +10 -0
  34. data/lib/backports/3.0.0/env.rb +3 -0
  35. data/lib/backports/3.0.0/hash/except.rb +10 -0
  36. data/lib/backports/3.0.0/hash/transform_keys.rb +48 -0
  37. data/lib/backports/3.0.0/hash.rb +3 -0
  38. data/lib/backports/3.0.0/ractor.rb +19 -0
  39. data/lib/backports/3.0.0/symbol/name.rb +21 -0
  40. data/lib/backports/3.0.0/symbol.rb +3 -0
  41. data/lib/backports/3.0.0.rb +3 -0
  42. data/lib/backports/3.0.rb +1 -0
  43. data/lib/backports/3.1.0/array/intersect.rb +16 -0
  44. data/lib/backports/3.1.0/array.rb +3 -0
  45. data/lib/backports/3.1.0/class/descendants.rb +11 -0
  46. data/lib/backports/3.1.0/class/subclasses.rb +11 -0
  47. data/lib/backports/3.1.0/class.rb +3 -0
  48. data/lib/backports/3.1.0/enumerable/compact.rb +5 -0
  49. data/lib/backports/3.1.0/enumerable/tally.rb +18 -0
  50. data/lib/backports/3.1.0/enumerable.rb +3 -0
  51. data/lib/backports/3.1.0/file/dirname.rb +16 -0
  52. data/lib/backports/3.1.0/file.rb +3 -0
  53. data/lib/backports/3.1.0/integer/try_convert.rb +7 -0
  54. data/lib/backports/3.1.0/integer.rb +3 -0
  55. data/lib/backports/3.1.0/match_data/match.rb +5 -0
  56. data/lib/backports/3.1.0/match_data/match_length.rb +6 -0
  57. data/lib/backports/3.1.0/match_data.rb +3 -0
  58. data/lib/backports/3.1.0/struct/keyword_init.rb +5 -0
  59. data/lib/backports/3.1.0/struct.rb +3 -0
  60. data/lib/backports/3.1.0.rb +3 -0
  61. data/lib/backports/3.1.rb +1 -0
  62. data/lib/backports/latest.rb +1 -1
  63. data/lib/backports/ractor/cloner.rb +103 -0
  64. data/lib/backports/ractor/errors.rb +20 -0
  65. data/lib/backports/ractor/filtered_queue.rb +205 -0
  66. data/lib/backports/ractor/queues.rb +66 -0
  67. data/lib/backports/ractor/ractor.rb +272 -0
  68. data/lib/backports/ractor/sharing.rb +97 -0
  69. data/lib/backports/version.rb +1 -1
  70. metadata +51 -8
data/backports.gemspec CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |gem|
23
23
  gem.require_paths = ["lib"]
24
24
 
25
25
  if gem.respond_to?(:metadata)
26
- gem.metadata['changelog_uri'] = 'https://github.com/marcandre/backports/blob/master/CHANGELOG.rdoc'
26
+ gem.metadata['changelog_uri'] = 'https://github.com/marcandre/backports/blob/master/CHANGELOG.md'
27
27
  gem.metadata['source_code_uri'] = 'https://github.com/marcandre/backports'
28
28
  gem.metadata['bug_tracker_uri'] = 'https://github.com/marcandre/backports/issues'
29
29
  end
@@ -1,5 +1,5 @@
1
1
  # require this file to load all the backports up to Ruby 2.0.0
2
- require 'backports/1.9'
2
+ require 'backports/1.9.3'
3
3
 
4
4
  if RUBY_VERSION < '2.0'
5
5
  Backports.warned[:require_std_lib] = true
@@ -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,3 +1,3 @@
1
1
  # require this file to load all the backports up to Ruby 2.1.0
2
- require 'backports/2.0'
2
+ require 'backports/2.0.0'
3
3
  Backports.require_relative_dir if RUBY_VERSION < '2.1'
@@ -4,7 +4,7 @@ unless String.method_defined? :unicode_normalize
4
4
  if (Regexp.compile("[\u{11100}-\u{11102}]") rescue false)
5
5
  class String
6
6
  def unicode_normalize(form = :nfc)
7
- require 'backports/tools/normalize.rb' unless defined? UnicodeNormalize
7
+ require 'backports/tools/normalize' unless defined? UnicodeNormalize
8
8
  ## The following line can be uncommented to avoid repeated checking for
9
9
  ## UnicodeNormalize. However, tests didn't show any noticeable speedup
10
10
  ## when doing this. This comment also applies to the commented out lines
@@ -14,13 +14,13 @@ unless String.method_defined? :unicode_normalize
14
14
  end
15
15
 
16
16
  def unicode_normalize!(form = :nfc)
17
- require 'backports/tools/normalize.rb' unless defined? UnicodeNormalize
17
+ require 'backports/tools/normalize' unless defined? UnicodeNormalize
18
18
  # String.send(:define_method, :unicode_normalize!, ->(form = :nfc) { replace(unicode_normalize(form)) } )
19
19
  replace(unicode_normalize(form))
20
20
  end
21
21
 
22
22
  def unicode_normalized?(form = :nfc)
23
- require 'backports/tools/normalize.rb' unless defined? UnicodeNormalize
23
+ require 'backports/tools/normalize' unless defined? UnicodeNormalize
24
24
  # String.send(:define_method, :unicode_normalized?, ->(form = :nfc) { UnicodeNormalize.normalized?(self, form) } )
25
25
  UnicodeNormalize.normalized?(self, form)
26
26
  end
@@ -1,3 +1,3 @@
1
1
  # require this file to load all the backports up to Ruby 2.2
2
- require 'backports/2.1'
2
+ require 'backports/2.1.0'
3
3
  Backports.require_relative_dir if RUBY_VERSION < '2.2'
@@ -0,0 +1,48 @@
1
+ unless Queue.method_defined? :close
2
+ require 'backports/tools/alias_method_chain'
3
+
4
+ class ClosedQueueError < StopIteration
5
+ end
6
+
7
+ class Queue
8
+ CLOSE_MESSAGE = Object.new
9
+
10
+ def push_with_close(arg)
11
+ raise ClosedQueueError, 'queue closed' if closed?
12
+
13
+ push_without_close(arg)
14
+ end
15
+ Backports.alias_method_chain self, :push, :close
16
+ alias_method :<<, :push
17
+ alias_method :enq, :push
18
+
19
+ def pop_with_close(non_block = false)
20
+ begin
21
+ r = pop_without_close(non_block || closed?)
22
+
23
+ r unless CLOSE_MESSAGE == r
24
+ rescue ThreadError
25
+ raise if non_block || !closed?
26
+ end
27
+ end
28
+ Backports.alias_method_chain self, :pop, :close
29
+
30
+ alias_method :shift, :pop
31
+ alias_method :deq, :pop
32
+
33
+ def close
34
+ @closed = true
35
+ 2.times do
36
+ Thread.pass
37
+ num_waiting.times do
38
+ push_without_close CLOSE_MESSAGE
39
+ end
40
+ end
41
+ self
42
+ end
43
+
44
+ def closed?
45
+ !!defined?(@closed)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,3 @@
1
+ require 'backports/tools/require_relative_dir'
2
+
3
+ Backports.require_relative_dir
@@ -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
@@ -1,3 +1,3 @@
1
1
  # require this file to load all the backports up to Ruby 2.3
2
- require 'backports/2.2'
2
+ require 'backports/2.2.0'
3
3
  Backports.require_relative_dir if RUBY_VERSION < '2.3'
@@ -0,0 +1,5 @@
1
+ class Bignum
2
+ def dup
3
+ self
4
+ end
5
+ end unless ((1 << 64).dup rescue false)
@@ -0,0 +1,3 @@
1
+ require 'backports/tools/require_relative_dir'
2
+
3
+ Backports.require_relative_dir
@@ -0,0 +1,7 @@
1
+ unless String.method_defined? :unpack1
2
+ class String
3
+ def unpack1(fmt)
4
+ unpack(fmt)[0]
5
+ end
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  # require this file to load all the backports up to Ruby 2.4
2
- require 'backports/2.3'
2
+ require 'backports/2.3.0'
3
3
  Backports.require_relative_dir if RUBY_VERSION < '2.4'
@@ -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
@@ -10,9 +10,16 @@ class Hash
10
10
 
11
11
  def transform_keys!
12
12
  return enum_for(:transform_keys!) { size } unless block_given?
13
- merge!({}) if frozen?
14
- keys.each do |key|
15
- self[yield(key)] = delete(key)
13
+
14
+ self[:trigger_error] = :immediately if frozen?
15
+
16
+ h = {}
17
+ begin
18
+ each do |key, value|
19
+ h[yield key] = value
20
+ end
21
+ ensure
22
+ replace(h)
16
23
  end
17
24
  self
18
25
  end unless method_defined? :transform_keys!
@@ -39,9 +39,9 @@ unless String.method_defined? :undump
39
39
  # * only allowing the first character after the \\ to not be alpha/num/space, so \\\\#@inst_var_access is ignored
40
40
  # To reduce the number of calls to eval a little, we wrap everything in a (...)+ so that consecutive escapes are
41
41
  # handled at the same time.
42
- result = string.gsub(/(\\+(u\{[\w ]+\}|[^cCM][\w]*))+/) do |s|
42
+ result = string.gsub(/(\\+(u\{[\w ]+\}|[^cCM]\w*))+/) do |s|
43
43
  begin
44
- eval("\"#{s}\"")
44
+ eval("\"#{s}\"") # "body"
45
45
  rescue SyntaxError => e
46
46
  raise RuntimeError, e.message, e.backtrace
47
47
  end
@@ -1,3 +1,3 @@
1
1
  # require this file to load all the backports up to Ruby 2.5
2
- require 'backports/2.4'
2
+ require 'backports/2.4.0'
3
3
  Backports.require_relative_dir if RUBY_VERSION < '2.5'
data/lib/backports/2.5.rb CHANGED
@@ -1,2 +1,2 @@
1
- # require this file to load all the backports of Ruby 2.4 and below
1
+ # require this file to load all the backports of Ruby 2.5 and below
2
2
  require 'backports/2.5.0'
@@ -8,6 +8,7 @@ unless Enumerable.method_defined? :chain
8
8
  Enumerator = Enumerable::Enumerator unless Object.const_defined? :Enumerator # For 1.8.x
9
9
 
10
10
  class Enumerator::Chain < Enumerator
11
+ # rubocop:disable Lint/MissingSuper
11
12
  def initialize(*enums)
12
13
  @enums = enums
13
14
  @rewindable = -1
@@ -16,6 +17,7 @@ unless Enumerable.method_defined? :chain
16
17
  # ...it checks what call of #initialize on non-initalized object returns
17
18
  self # rubocop:disable Lint/Void
18
19
  end
20
+ # rubocop:enable Lint/MissingSuper
19
21
 
20
22
  def each(*args, &block)
21
23
  @enums.each_with_index do |enum, i|
@@ -1,3 +1,3 @@
1
- # require this file to load all the backports up to Ruby 2.5
2
- require 'backports/2.5'
1
+ # require this file to load all the backports up to Ruby 2.6
2
+ require 'backports/2.5.0'
3
3
  Backports.require_relative_dir if RUBY_VERSION < '2.6'
data/lib/backports/2.6.rb CHANGED
@@ -1,2 +1,2 @@
1
- # require this file to load all the backports of Ruby 2.4 and below
1
+ # require this file to load all the backports of Ruby 2.6 and below
2
2
  require 'backports/2.6.0'
@@ -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,9 @@
1
+ require 'backports/1.8.7/string/end_with' unless String.method_defined? :end_with?
2
+
3
+ unless Symbol.method_defined?(:end_with?)
4
+ class Symbol
5
+ def end_with?(*suffixes)
6
+ to_s.end_with?(*suffixes)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ require 'backports/tools/require_relative_dir'
2
+
3
+ Backports.require_relative_dir
@@ -1,3 +1,3 @@
1
- # require this file to load all the backports up to Ruby 2.5
2
- require 'backports/2.6'
1
+ # require this file to load all the backports up to Ruby 2.7
2
+ require 'backports/2.6.0'
3
3
  Backports.require_relative_dir if RUBY_VERSION < '2.7'
@@ -0,0 +1,10 @@
1
+ class << ENV
2
+ def except(*keys)
3
+ if keys.size > 4 && size > 4 # index if O(m*n) is big
4
+ h = {}
5
+ keys.each { |key| h[key] = true }
6
+ keys = h
7
+ end
8
+ reject { |key, _value| keys.include? key}
9
+ end
10
+ end unless ENV.respond_to? :except
@@ -0,0 +1,3 @@
1
+ require 'backports/tools/require_relative_dir'
2
+
3
+ Backports.require_relative_dir
@@ -0,0 +1,10 @@
1
+ class Hash
2
+ def except(*keys)
3
+ if keys.size > 4 && size > 4 # index if O(m*n) is big
4
+ h = {}
5
+ keys.each { |key| h[key] = true }
6
+ keys = h
7
+ end
8
+ reject { |key, _value| keys.include? key}
9
+ end
10
+ end unless Hash.method_defined? :except
@@ -0,0 +1,48 @@
1
+ class Hash
2
+ unless ({}.transform_keys(:x => 1) rescue false)
3
+ require 'backports/2.5.0/hash/transform_keys'
4
+ require 'backports/tools/alias_method_chain'
5
+
6
+ def transform_keys_with_hash_arg(hash = not_given = true, &block)
7
+ return to_enum(:transform_keys) { size } if not_given && !block
8
+
9
+ return transform_keys_without_hash_arg(&block) if not_given
10
+
11
+ h = {}
12
+ if block_given?
13
+ each do |key, value|
14
+ h[hash.fetch(key) { yield key }] = value
15
+ end
16
+ else
17
+ each do |key, value|
18
+ h[hash.fetch(key, key)] = value
19
+ end
20
+ end
21
+ h
22
+ end
23
+ Backports.alias_method_chain self, :transform_keys, :hash_arg
24
+
25
+ def transform_keys_with_hash_arg!(hash = not_given = true, &block)
26
+ return enum_for(:transform_keys!) { size } if not_given && !block
27
+
28
+ return transform_keys_without_hash_arg!(&block) if not_given
29
+
30
+ h = {}
31
+ begin
32
+ if block_given?
33
+ each do |key, value|
34
+ h[hash.fetch(key) { yield key }] = value
35
+ end
36
+ else
37
+ each do |key, value|
38
+ h[hash.fetch(key, key)] = value
39
+ end
40
+ end
41
+ ensure
42
+ replace(h)
43
+ end
44
+ self
45
+ end
46
+ Backports.alias_method_chain self, :transform_keys!, :hash_arg
47
+ end
48
+ end
@@ -0,0 +1,3 @@
1
+ require 'backports/tools/require_relative_dir'
2
+
3
+ Backports.require_relative_dir
@@ -0,0 +1,19 @@
1
+ if RUBY_VERSION < '2'
2
+ warn 'Ractor not backported to Ruby 1.x'
3
+ elsif defined?(Ractor.current)
4
+ # all good
5
+ else
6
+ # Cloner:
7
+ require_relative '../2.4.0/hash/transform_values'
8
+ require_relative '../2.5.0/hash/transform_keys'
9
+ # Queues & FilteredQueue
10
+ require_relative '../2.3.0/queue/close'
11
+
12
+ class Ractor
13
+ end
14
+
15
+ module Backports
16
+ Ractor = ::Ractor
17
+ end
18
+ require_relative '../ractor/ractor'
19
+ end
@@ -0,0 +1,21 @@
1
+ unless Symbol.method_defined? :name
2
+ if ((ObjectSpace::WeakMap.new[:test] = :test) rescue false)
3
+ # WeakMaps accept symbols only in Ruby 2.7+
4
+ def Backports.symbol_names
5
+ @symbol_names ||= ObjectSpace::WeakMap.new
6
+ end
7
+
8
+ class Symbol
9
+ def name
10
+ Backports.symbol_names[self] ||= to_s.freeze
11
+ end
12
+ end
13
+ else
14
+ # For earlier Rubies, we can't pool their strings
15
+ class Symbol
16
+ def name
17
+ to_s.freeze
18
+ end
19
+ end
20
+ end
21
+ 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/2.7.0'
3
+ Backports.require_relative_dir if RUBY_VERSION < '3.0'
@@ -0,0 +1 @@
1
+ require 'backports/3.0.0'
@@ -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,7 @@
1
+ class Integer
2
+ require 'backports/tools/arguments'
3
+
4
+ def self.try_convert(obj)
5
+ ::Backports.try_convert(obj, ::Integer, :to_int)
6
+ end
7
+ 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'