backports 3.21.0 → 3.23.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +401 -304
- data/Gemfile +1 -1
- data/README.md +288 -159
- data/lib/backports/2.1.0/module/singleton_class.rb +8 -0
- data/lib/backports/2.3.0/struct/dig.rb +2 -0
- data/lib/backports/2.5.0/dir/children.rb +4 -0
- data/lib/backports/2.5.0/dir/each_child.rb +7 -0
- data/lib/backports/2.7.0/complex/{comparision.rb → comparison.rb} +0 -0
- data/lib/backports/2.7.0/enumerable/tally.rb +4 -3
- data/lib/backports/2.7.0/symbol/end_with.rb +9 -0
- data/lib/backports/2.7.0/symbol.rb +3 -0
- data/lib/backports/3.0.0/symbol/name.rb +16 -6
- data/lib/backports/3.1.0/array/intersect.rb +16 -0
- data/lib/backports/3.1.0/array.rb +3 -0
- data/lib/backports/3.1.0/class/descendants.rb +11 -0
- data/lib/backports/3.1.0/class/subclasses.rb +11 -0
- data/lib/backports/3.1.0/class.rb +3 -0
- data/lib/backports/3.1.0/enumerable/compact.rb +5 -0
- data/lib/backports/3.1.0/enumerable/tally.rb +18 -0
- data/lib/backports/3.1.0/enumerable.rb +3 -0
- data/lib/backports/3.1.0/file/dirname.rb +16 -0
- data/lib/backports/3.1.0/file.rb +3 -0
- data/lib/backports/3.1.0/integer/try_convert.rb +7 -0
- data/lib/backports/3.1.0/integer.rb +3 -0
- data/lib/backports/3.1.0/match_data/match.rb +5 -0
- data/lib/backports/3.1.0/match_data/match_length.rb +6 -0
- data/lib/backports/3.1.0/match_data.rb +3 -0
- data/lib/backports/3.1.0/struct/keyword_init.rb +5 -0
- data/lib/backports/3.1.0/struct.rb +3 -0
- data/lib/backports/3.1.0.rb +3 -0
- data/lib/backports/3.1.rb +1 -0
- data/lib/backports/latest.rb +1 -1
- data/lib/backports/version.rb +1 -1
- metadata +26 -4
@@ -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
|
File without changes
|
@@ -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
|
-
|
6
|
+
each_entry { |item| h[item] = h.fetch(item, 0) + 1 }
|
7
|
+
|
8
|
+
h
|
8
9
|
end
|
9
10
|
end
|
10
11
|
end
|
@@ -1,11 +1,21 @@
|
|
1
1
|
unless Symbol.method_defined? :name
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
-
|
7
|
-
|
8
|
-
|
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,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,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,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 @@
|
|
1
|
+
require 'backports/3.1.0'
|
data/lib/backports/latest.rb
CHANGED
data/lib/backports/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Backports
|
2
|
-
VERSION = "3.
|
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.
|
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-
|
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
|
@@ -524,12 +525,14 @@ files:
|
|
524
525
|
- lib/backports/2.7.0/comparable.rb
|
525
526
|
- lib/backports/2.7.0/comparable/clamp.rb
|
526
527
|
- lib/backports/2.7.0/complex.rb
|
527
|
-
- lib/backports/2.7.0/complex/
|
528
|
+
- lib/backports/2.7.0/complex/comparison.rb
|
528
529
|
- lib/backports/2.7.0/enumerable.rb
|
529
530
|
- lib/backports/2.7.0/enumerable/filter_map.rb
|
530
531
|
- lib/backports/2.7.0/enumerable/tally.rb
|
531
532
|
- lib/backports/2.7.0/enumerator.rb
|
532
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
|
533
536
|
- lib/backports/2.7.0/time/ceil.rb
|
534
537
|
- lib/backports/2.7.0/time/floor.rb
|
535
538
|
- lib/backports/2.7.rb
|
@@ -543,6 +546,25 @@ files:
|
|
543
546
|
- lib/backports/3.0.0/symbol.rb
|
544
547
|
- lib/backports/3.0.0/symbol/name.rb
|
545
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
|
546
568
|
- lib/backports/basic_object.rb
|
547
569
|
- lib/backports/force/array_map.rb
|
548
570
|
- lib/backports/force/enumerable_map.rb
|
@@ -605,7 +627,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
605
627
|
- !ruby/object:Gem::Version
|
606
628
|
version: '0'
|
607
629
|
requirements: []
|
608
|
-
rubygems_version: 3.
|
630
|
+
rubygems_version: 3.3.3
|
609
631
|
signing_key:
|
610
632
|
specification_version: 4
|
611
633
|
summary: Backports of Ruby features for older Ruby.
|