backports 3.20.2 → 3.23.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +401 -304
  3. data/Gemfile +1 -1
  4. data/README.md +288 -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.7.0/complex/{comparision.rb → comparison.rb} +0 -0
  11. data/lib/backports/2.7.0/enumerable/tally.rb +4 -3
  12. data/lib/backports/2.7.0/symbol/end_with.rb +9 -0
  13. data/lib/backports/2.7.0/symbol.rb +3 -0
  14. data/lib/backports/3.0.0/symbol/name.rb +16 -6
  15. data/lib/backports/3.1.0/array/intersect.rb +16 -0
  16. data/lib/backports/3.1.0/array.rb +3 -0
  17. data/lib/backports/3.1.0/class/descendants.rb +11 -0
  18. data/lib/backports/3.1.0/class/subclasses.rb +11 -0
  19. data/lib/backports/3.1.0/class.rb +3 -0
  20. data/lib/backports/3.1.0/enumerable/compact.rb +5 -0
  21. data/lib/backports/3.1.0/enumerable/tally.rb +18 -0
  22. data/lib/backports/3.1.0/enumerable.rb +3 -0
  23. data/lib/backports/3.1.0/file/dirname.rb +16 -0
  24. data/lib/backports/3.1.0/file.rb +3 -0
  25. data/lib/backports/3.1.0/integer/try_convert.rb +7 -0
  26. data/lib/backports/3.1.0/integer.rb +3 -0
  27. data/lib/backports/3.1.0/match_data/match.rb +5 -0
  28. data/lib/backports/3.1.0/match_data/match_length.rb +6 -0
  29. data/lib/backports/3.1.0/match_data.rb +3 -0
  30. data/lib/backports/3.1.0/struct/keyword_init.rb +5 -0
  31. data/lib/backports/3.1.0/struct.rb +3 -0
  32. data/lib/backports/3.1.0.rb +3 -0
  33. data/lib/backports/3.1.rb +1 -0
  34. data/lib/backports/latest.rb +1 -1
  35. data/lib/backports/ractor/cloner.rb +13 -4
  36. data/lib/backports/version.rb +1 -1
  37. metadata +27 -4
@@ -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,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
@@ -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
@@ -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
@@ -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,11 +1,21 @@
1
1
  unless Symbol.method_defined? :name
2
- def Backports.symbol_names
3
- @symbol_names ||= ObjectSpace::WeakMap.new
4
- end
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
5
7
 
6
- class Symbol
7
- def name
8
- Backports.symbol_names[self] ||= to_s.freeze
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
9
19
  end
10
20
  end
11
21
  end
@@ -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'
@@ -4,14 +4,23 @@ using ::RubyNext if defined?(::RubyNext)
4
4
 
5
5
  module Backports
6
6
  class Ractor
7
- module Cloner
8
- extend self
7
+ class Cloner
8
+ class << self
9
+ def deep_clone(obj)
10
+ return obj if Ractor.ractor_shareable_self?(obj, false) { false }
9
11
 
10
- def deep_clone(obj)
11
- return obj if Ractor.ractor_shareable_self?(obj, false) { false }
12
+ new.deep_clone(obj)
13
+ end
14
+
15
+ private :new
16
+ end
12
17
 
18
+ def initialize
13
19
  @processed = {}.compare_by_identity
14
20
  @changed = nil
21
+ end
22
+
23
+ def deep_clone(obj)
15
24
  result = process(obj) do |r|
16
25
  copy_contents(r)
17
26
  end
@@ -1,3 +1,3 @@
1
1
  module Backports
2
- VERSION = "3.20.2" unless Backports.constants.include? :VERSION # the guard is against a redefinition warning that happens on Travis
2
+ VERSION = "3.23.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.20.2
4
+ version: 3.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc-André Lafortune
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-27 00:00:00.000000000 Z
11
+ date: 2021-12-28 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.
@@ -391,6 +391,7 @@ files:
391
391
  - lib/backports/2.1.0/fixnum/bit_length.rb
392
392
  - lib/backports/2.1.0/module.rb
393
393
  - lib/backports/2.1.0/module/include.rb
394
+ - lib/backports/2.1.0/module/singleton_class.rb
394
395
  - lib/backports/2.1.rb
395
396
  - lib/backports/2.2.0.rb
396
397
  - lib/backports/2.2.0/enumerable.rb
@@ -455,6 +456,7 @@ files:
455
456
  - lib/backports/2.4.0/regexp/match.rb
456
457
  - lib/backports/2.4.0/string.rb
457
458
  - lib/backports/2.4.0/string/match.rb
459
+ - lib/backports/2.4.0/string/unpack1.rb
458
460
  - lib/backports/2.4.0/true_class.rb
459
461
  - lib/backports/2.4.0/true_class/dup.rb
460
462
  - lib/backports/2.4.rb
@@ -523,12 +525,14 @@ files:
523
525
  - lib/backports/2.7.0/comparable.rb
524
526
  - lib/backports/2.7.0/comparable/clamp.rb
525
527
  - lib/backports/2.7.0/complex.rb
526
- - lib/backports/2.7.0/complex/comparision.rb
528
+ - lib/backports/2.7.0/complex/comparison.rb
527
529
  - lib/backports/2.7.0/enumerable.rb
528
530
  - lib/backports/2.7.0/enumerable/filter_map.rb
529
531
  - lib/backports/2.7.0/enumerable/tally.rb
530
532
  - lib/backports/2.7.0/enumerator.rb
531
533
  - lib/backports/2.7.0/enumerator/produce.rb
534
+ - lib/backports/2.7.0/symbol.rb
535
+ - lib/backports/2.7.0/symbol/end_with.rb
532
536
  - lib/backports/2.7.0/time/ceil.rb
533
537
  - lib/backports/2.7.0/time/floor.rb
534
538
  - lib/backports/2.7.rb
@@ -542,6 +546,25 @@ files:
542
546
  - lib/backports/3.0.0/symbol.rb
543
547
  - lib/backports/3.0.0/symbol/name.rb
544
548
  - lib/backports/3.0.rb
549
+ - lib/backports/3.1.0.rb
550
+ - lib/backports/3.1.0/array.rb
551
+ - lib/backports/3.1.0/array/intersect.rb
552
+ - lib/backports/3.1.0/class.rb
553
+ - lib/backports/3.1.0/class/descendants.rb
554
+ - lib/backports/3.1.0/class/subclasses.rb
555
+ - lib/backports/3.1.0/enumerable.rb
556
+ - lib/backports/3.1.0/enumerable/compact.rb
557
+ - lib/backports/3.1.0/enumerable/tally.rb
558
+ - lib/backports/3.1.0/file.rb
559
+ - lib/backports/3.1.0/file/dirname.rb
560
+ - lib/backports/3.1.0/integer.rb
561
+ - lib/backports/3.1.0/integer/try_convert.rb
562
+ - lib/backports/3.1.0/match_data.rb
563
+ - lib/backports/3.1.0/match_data/match.rb
564
+ - lib/backports/3.1.0/match_data/match_length.rb
565
+ - lib/backports/3.1.0/struct.rb
566
+ - lib/backports/3.1.0/struct/keyword_init.rb
567
+ - lib/backports/3.1.rb
545
568
  - lib/backports/basic_object.rb
546
569
  - lib/backports/force/array_map.rb
547
570
  - lib/backports/force/enumerable_map.rb
@@ -604,7 +627,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
604
627
  - !ruby/object:Gem::Version
605
628
  version: '0'
606
629
  requirements: []
607
- rubygems_version: 3.1.4
630
+ rubygems_version: 3.3.3
608
631
  signing_key:
609
632
  specification_version: 4
610
633
  summary: Backports of Ruby features for older Ruby.