polyfill 1.7.0 → 1.8.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/.travis.yml +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +13 -13
- data/lib/polyfill.rb +7 -0
- data/lib/polyfill/v2_6.rb +3 -0
- data/lib/polyfill/v2_6/array.rb +24 -0
- data/lib/polyfill/v2_6/enumerable.rb +29 -0
- data/lib/polyfill/v2_6/hash.rb +27 -9
- data/lib/polyfill/v2_6/kernel.rb +45 -0
- data/lib/polyfill/v2_6/open_struct.rb +31 -0
- data/lib/polyfill/v2_6/struct.rb +29 -0
- data/lib/polyfill/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 055be265874af4c56f4902c479982779ac2db965d666553ccf5f22ba6fb31fb7
|
4
|
+
data.tar.gz: 139e5bb51a76000559dbb71560e10f32c7eaed37faa8c1dbd7fbc0e8be91dcee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 603bd2a32b554f123d602fc455a5c970c9309530a8f585a51d6feeba8044887f24baecb4d56bbdb9881eaec6f02c7e9babadd406132c5c3d591fb5991b2f458e
|
7
|
+
data.tar.gz: 2ab11f404cdc0d19d46fd17560a18fff30fc7e8c94144fd7960e22f9525c00a3159c2297d294be3856e08f1978cdd75b48dbeea685aa1122e4affc9a5652ac05
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
# [1.8.0][] (TBD)
|
2
|
+
|
3
|
+
## Added
|
4
|
+
|
5
|
+
- v2.6 Kernel#Complex
|
6
|
+
- v2.6 Kernel#Float
|
7
|
+
- v2.6 Kernel#Integer
|
8
|
+
- v2.6 Kernel#Rational
|
9
|
+
- v2.6 Array#to_h
|
10
|
+
- v2.6 Hash#to_h
|
11
|
+
- v2.6 Enumerable#to_h
|
12
|
+
- v2.6 OpenStruct#to_h
|
13
|
+
- v2.6 Struct#to_h
|
14
|
+
|
1
15
|
# [1.7.0][] (2019-02-17)
|
2
16
|
|
3
17
|
## Added
|
@@ -274,6 +288,7 @@ incorrect type was passed:
|
|
274
288
|
- v2.4 String#concat?
|
275
289
|
- v2.4 String#prepend?
|
276
290
|
|
291
|
+
[1.8.0]: https://github.com/AaronLasseigne/polyfill/compare/v1.7.0...v1.8.0
|
277
292
|
[1.7.0]: https://github.com/AaronLasseigne/polyfill/compare/v1.6.0...v1.7.0
|
278
293
|
[1.6.0]: https://github.com/AaronLasseigne/polyfill/compare/v1.5.0...v1.6.0
|
279
294
|
[1.5.0]: https://github.com/AaronLasseigne/polyfill/compare/v1.4.0...v1.5.0
|
data/README.md
CHANGED
@@ -28,7 +28,7 @@ monkey patching** that may cause issues outside of your use.
|
|
28
28
|
Add it to your Gemfile:
|
29
29
|
|
30
30
|
```ruby
|
31
|
-
gem 'polyfill', '~> 1.
|
31
|
+
gem 'polyfill', '~> 1.8'
|
32
32
|
```
|
33
33
|
|
34
34
|
Or install it manually:
|
@@ -133,7 +133,7 @@ table. The explanation will follow "**Differences:**".
|
|
133
133
|
| ✓ | Array | #difference | New
|
134
134
|
| ✗ | | #filter | New (alias of `select`)
|
135
135
|
| ✗ | | #filter! | New (alias of `select!`)
|
136
|
-
|
|
136
|
+
| ✓ | | #to_h | Accepts a block that maps elements to new key/value pairs.
|
137
137
|
| ✓ | | #union | New
|
138
138
|
| ✗ | Binding | #source_location | New
|
139
139
|
| ✗ | Coverage | .line_stub | New
|
@@ -144,7 +144,7 @@ table. The explanation will follow "**Differences:**".
|
|
144
144
|
| ✗ | Enumerable | #+ | New
|
145
145
|
| ✗ | | #chain | New
|
146
146
|
| ✗ | | #filter | New (alias of `select`)
|
147
|
-
|
|
147
|
+
| ✓ | | #to_h | Accepts a block that maps elements to new key/value pairs.
|
148
148
|
| ✗ | Enumerator::Lazy | #filter | New (alias of `select`)
|
149
149
|
| ✗ | ENV | #to_h | Accepts a block that maps elements to new key/value pairs.
|
150
150
|
| ✗ | ERB | .new | Accepts new optional keyword arguments, `:eoutvar` and `:trim_mode`.
|
@@ -160,14 +160,14 @@ table. The explanation will follow "**Differences:**".
|
|
160
160
|
| ✗ | | #filter! | New (alias of `select!`)
|
161
161
|
| ✓ | | #merge | Accepts multiple arguments.
|
162
162
|
| ✓ | | #merge! | Accepts multiple arguments.
|
163
|
-
|
|
163
|
+
| ✓ | | #to_h | Accepts a block that maps elements to new key/value pairs.
|
164
164
|
| ✓ | | #update | Accepts multiple arguments.
|
165
165
|
| ✗ | Kernel | #BigDecimal | Accepts a new optional keyword argument, `:exception`.
|
166
|
-
|
|
166
|
+
| ✓ | | #Complex | Accepts a new optional keyword argument, `:exception`.
|
167
167
|
| ✗ | | #exec | Does not close non-standard file descriptors.
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
168
|
+
| ✓ | | #Float | Accepts a new optional keyword argument, `:exception`.
|
169
|
+
| ✓ | | #Integer | Accepts a new optional keyword argument, `:exception`.
|
170
|
+
| ✓ | | #Rational | Accepts a new optional keyword argument, `:exception`.
|
171
171
|
| ✓ | | #then | New (alias of `yield_self`)
|
172
172
|
| ✗ | | #system | Accepts a new optional keyword argument, `:exception`. Does not close non-standard file descriptors.
|
173
173
|
| ✗ | KeyError | .new | Accepts new optional keyword arguments, `:receiver` and `:key`.
|
@@ -178,9 +178,9 @@ table. The explanation will follow "**Differences:**".
|
|
178
178
|
| ✗ | | #skew_symmetric? | New
|
179
179
|
| ✗ | Method | #<< | New
|
180
180
|
| ✗ | | #>> | New
|
181
|
-
| ✗ | Module | #method_defined? | Accepts a second optional argument (default: `true`). If `false`, it only checks the class and not the
|
182
|
-
| ✗ | | #private_method_defined? | Accepts a second optional argument (default: `true`). If `false`, it only checks the class and not the
|
183
|
-
| ✗ | | #protected_method_defined? | Accepts a second optional argument (default: `true`). If `false`, it only checks the class and not the
|
181
|
+
| ✗ | Module | #method_defined? | Accepts a second optional argument (default: `true`). If `false`, it only checks the class and not the ancestors.
|
182
|
+
| ✗ | | #private_method_defined? | Accepts a second optional argument (default: `true`). If `false`, it only checks the class and not the ancestors.
|
183
|
+
| ✗ | | #protected_method_defined? | Accepts a second optional argument (default: `true`). If `false`, it only checks the class and not the ancestors.
|
184
184
|
| ✗ | NameError | .new | Accepts new optional keyword arguments, `:receiver` and `:key`.
|
185
185
|
| ✗ | Net::HTTP | .new | Accepts a new optional keyword argument, `:write_timeout`.
|
186
186
|
| ✗ | | #write_timeout | New
|
@@ -188,7 +188,7 @@ table. The explanation will follow "**Differences:**".
|
|
188
188
|
| ✗ | NilClass | #=~ | New
|
189
189
|
| ✗ | NoMethodError | .new | Accepts new optional keyword arguments, `:receiver` and `:key`.
|
190
190
|
| ✗ | Numeric | #step | Now returns an instance of the Enumerator::ArithmeticSequence class rather than one of the Enumerator class.
|
191
|
-
|
|
191
|
+
| ✓ | OpenStruct | #to_h | Accepts a block that maps keys and values to new keys and values.
|
192
192
|
| ✗ | Proc | #<< | New
|
193
193
|
| ✗ | | #>> | New
|
194
194
|
| ✗ | | .call | No longer changes `$SAFE`.
|
@@ -201,7 +201,7 @@ table. The explanation will follow "**Differences:**".
|
|
201
201
|
| ✗ | Set | #filter! | New (alias of `select!`)
|
202
202
|
| ✓ | String | #split | Yields each substring to a block if given.
|
203
203
|
| ✗ | Struct | #filter | New (alias of `select`)
|
204
|
-
|
|
204
|
+
| ✓ | | #to_h | Accepts a block that maps keys and values to new keys and values.
|
205
205
|
| ✗ | Time | #+ | Preserves the timezone.
|
206
206
|
| ✗ | | #- | Preserves the timezone.
|
207
207
|
| ✗ | | .new | Accepts a timezone object as well as a UTC offset string.
|
data/lib/polyfill.rb
CHANGED
@@ -203,6 +203,13 @@ def Polyfill(options = {}) # rubocop:disable Naming/MethodName
|
|
203
203
|
refine Object.const_get(klass, false) do
|
204
204
|
include instance_module
|
205
205
|
|
206
|
+
# Certain Kernel methods are private outside of Kernel
|
207
|
+
if klass == 'Object'
|
208
|
+
%i[Complex Float Integer Rational].each do |method|
|
209
|
+
private method if methods_added.include?(method)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
206
213
|
if native
|
207
214
|
Polyfill::InternalUtils.ignore_warnings do
|
208
215
|
define_method :respond_to? do |name, include_all = false|
|
data/lib/polyfill/v2_6.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
require_relative 'v2_6/array'
|
2
|
+
require_relative 'v2_6/enumerable'
|
2
3
|
require_relative 'v2_6/hash'
|
3
4
|
require_relative 'v2_6/kernel'
|
5
|
+
require_relative 'v2_6/open_struct'
|
4
6
|
require_relative 'v2_6/string'
|
7
|
+
require_relative 'v2_6/struct'
|
5
8
|
|
6
9
|
module Polyfill
|
7
10
|
module V2_6
|
data/lib/polyfill/v2_6/array.rb
CHANGED
@@ -7,6 +7,30 @@ module Polyfill
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
+
def to_h
|
11
|
+
return super unless block_given?
|
12
|
+
|
13
|
+
block = ::Proc.new
|
14
|
+
|
15
|
+
pairs = map.with_index do |elem, i|
|
16
|
+
pair = block.call(elem)
|
17
|
+
|
18
|
+
unless pair.respond_to?(:to_ary)
|
19
|
+
raise TypeError, "wrong element type #{pair.class} at #{i} (expected array)"
|
20
|
+
end
|
21
|
+
|
22
|
+
pair = pair.to_ary
|
23
|
+
|
24
|
+
unless pair.length == 2
|
25
|
+
raise ArgumentError, "wrong array length at #{i} (expected 2, was #{pair.length})"
|
26
|
+
end
|
27
|
+
|
28
|
+
pair
|
29
|
+
end
|
30
|
+
|
31
|
+
pairs.to_h
|
32
|
+
end
|
33
|
+
|
10
34
|
def union(*arrays)
|
11
35
|
return self | [] if arrays.empty?
|
12
36
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Polyfill
|
2
|
+
module V2_6
|
3
|
+
module Enumerable
|
4
|
+
def to_h
|
5
|
+
return super unless block_given?
|
6
|
+
|
7
|
+
block = ::Proc.new
|
8
|
+
|
9
|
+
pairs = map do |elem|
|
10
|
+
pair = block.call(elem)
|
11
|
+
|
12
|
+
unless pair.respond_to?(:to_ary)
|
13
|
+
raise TypeError, "wrong element type #{pair.class} (expected array)"
|
14
|
+
end
|
15
|
+
|
16
|
+
pair = pair.to_ary
|
17
|
+
|
18
|
+
unless pair.length == 2
|
19
|
+
raise ArgumentError, "element has wrong array length (expected 2, was #{pair.length})"
|
20
|
+
end
|
21
|
+
|
22
|
+
pair
|
23
|
+
end
|
24
|
+
|
25
|
+
pairs.to_h
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/polyfill/v2_6/hash.rb
CHANGED
@@ -1,12 +1,34 @@
|
|
1
1
|
module Polyfill
|
2
2
|
module V2_6
|
3
3
|
module Hash
|
4
|
+
def to_h
|
5
|
+
return super unless block_given?
|
6
|
+
|
7
|
+
block = ::Proc.new
|
8
|
+
|
9
|
+
pairs = map do |k, v|
|
10
|
+
pair = block.call(k, v)
|
11
|
+
|
12
|
+
unless pair.respond_to?(:to_ary)
|
13
|
+
raise TypeError, "wrong element type #{pair.class} (expected array)"
|
14
|
+
end
|
15
|
+
|
16
|
+
pair = pair.to_ary
|
17
|
+
|
18
|
+
unless pair.length == 2
|
19
|
+
raise ArgumentError, "element has wrong array length (expected 2, was #{pair.length})"
|
20
|
+
end
|
21
|
+
|
22
|
+
pair
|
23
|
+
end
|
24
|
+
|
25
|
+
pairs.to_h
|
26
|
+
end
|
27
|
+
|
4
28
|
def merge(*args)
|
5
29
|
if block_given?
|
6
|
-
block = ::Proc.new
|
7
|
-
|
8
30
|
args.each_with_object(dup) do |arg, h|
|
9
|
-
h.merge!(arg,
|
31
|
+
h.merge!(arg, &::Proc.new)
|
10
32
|
end
|
11
33
|
else
|
12
34
|
args.each_with_object(dup) do |arg, h|
|
@@ -17,10 +39,8 @@ module Polyfill
|
|
17
39
|
|
18
40
|
def merge!(*args)
|
19
41
|
if block_given?
|
20
|
-
block = ::Proc.new
|
21
|
-
|
22
42
|
args.each_with_object(self) do |arg, h|
|
23
|
-
h.merge!(arg,
|
43
|
+
h.merge!(arg, &::Proc.new)
|
24
44
|
end
|
25
45
|
else
|
26
46
|
args.each_with_object(self) do |arg, h|
|
@@ -31,10 +51,8 @@ module Polyfill
|
|
31
51
|
|
32
52
|
def update(*args)
|
33
53
|
if block_given?
|
34
|
-
block = ::Proc.new
|
35
|
-
|
36
54
|
args.each_with_object(self) do |arg, h|
|
37
|
-
h.update(arg,
|
55
|
+
h.update(arg, &::Proc.new)
|
38
56
|
end
|
39
57
|
else
|
40
58
|
args.each_with_object(self) do |arg, h|
|
data/lib/polyfill/v2_6/kernel.rb
CHANGED
@@ -3,6 +3,51 @@ module Polyfill
|
|
3
3
|
module Kernel
|
4
4
|
using Polyfill(Kernel: %w[#yield_self], version: '2.5')
|
5
5
|
|
6
|
+
def Complex(*args, exception: true) # rubocop:disable Naming/MethodName
|
7
|
+
super(*args) if exception
|
8
|
+
|
9
|
+
x, y = *args
|
10
|
+
if !x.nil? && !x.is_a?(::String) && !x.is_a?(::Numeric) && !y.nil? && y.is_a?(::Numeric)
|
11
|
+
raise ::TypeError, 'not a real'
|
12
|
+
end
|
13
|
+
|
14
|
+
begin
|
15
|
+
super(*args)
|
16
|
+
rescue ::ArgumentError, ::TypeError
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def Float(arg, exception: true) # rubocop:disable Naming/MethodName
|
22
|
+
super(arg) if exception
|
23
|
+
|
24
|
+
begin
|
25
|
+
super(arg)
|
26
|
+
rescue ::ArgumentError, ::TypeError
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def Integer(arg, exception: true) # rubocop:disable Naming/MethodName
|
32
|
+
super(arg) if exception
|
33
|
+
|
34
|
+
begin
|
35
|
+
super(arg)
|
36
|
+
rescue ::ArgumentError, ::TypeError, ::FloatDomainError
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def Rational(*args, exception: true) # rubocop:disable Naming/MethodName
|
42
|
+
super(*args) if exception
|
43
|
+
|
44
|
+
begin
|
45
|
+
super(*args)
|
46
|
+
rescue ::ArgumentError, ::TypeError
|
47
|
+
nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
6
51
|
def then
|
7
52
|
return yield_self unless block_given?
|
8
53
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
module Polyfill
|
4
|
+
module V2_6
|
5
|
+
module OpenStruct
|
6
|
+
def to_h
|
7
|
+
return super unless block_given?
|
8
|
+
|
9
|
+
block = ::Proc.new
|
10
|
+
|
11
|
+
pairs = each_pair.map do |k, v|
|
12
|
+
pair = block.call(k, v)
|
13
|
+
|
14
|
+
unless pair.respond_to?(:to_ary)
|
15
|
+
raise TypeError, "wrong element type #{pair.class} (expected array)"
|
16
|
+
end
|
17
|
+
|
18
|
+
pair = pair.to_ary
|
19
|
+
|
20
|
+
unless pair.length == 2
|
21
|
+
raise ArgumentError, "element has wrong array length (expected 2, was #{pair.length})"
|
22
|
+
end
|
23
|
+
|
24
|
+
pair
|
25
|
+
end
|
26
|
+
|
27
|
+
pairs.to_h
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Polyfill
|
2
|
+
module V2_6
|
3
|
+
module Struct
|
4
|
+
def to_h
|
5
|
+
return super unless block_given?
|
6
|
+
|
7
|
+
block = ::Proc.new
|
8
|
+
|
9
|
+
pairs = each_pair.map do |k, v|
|
10
|
+
pair = block.call(k, v)
|
11
|
+
|
12
|
+
unless pair.respond_to?(:to_ary)
|
13
|
+
raise TypeError, "wrong element type #{pair.class} (expected array)"
|
14
|
+
end
|
15
|
+
|
16
|
+
pair = pair.to_ary
|
17
|
+
|
18
|
+
unless pair.length == 2
|
19
|
+
raise ArgumentError, "element has wrong array length (expected 2, was #{pair.length})"
|
20
|
+
end
|
21
|
+
|
22
|
+
pair
|
23
|
+
end
|
24
|
+
|
25
|
+
pairs.to_h
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/polyfill/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polyfill
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Lasseigne
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02
|
11
|
+
date: 2019-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -123,9 +123,12 @@ files:
|
|
123
123
|
- lib/polyfill/v2_5/time.rb
|
124
124
|
- lib/polyfill/v2_6.rb
|
125
125
|
- lib/polyfill/v2_6/array.rb
|
126
|
+
- lib/polyfill/v2_6/enumerable.rb
|
126
127
|
- lib/polyfill/v2_6/hash.rb
|
127
128
|
- lib/polyfill/v2_6/kernel.rb
|
129
|
+
- lib/polyfill/v2_6/open_struct.rb
|
128
130
|
- lib/polyfill/v2_6/string.rb
|
131
|
+
- lib/polyfill/v2_6/struct.rb
|
129
132
|
- lib/polyfill/version.rb
|
130
133
|
- polyfill.gemspec
|
131
134
|
homepage: ''
|
@@ -147,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
150
|
- !ruby/object:Gem::Version
|
148
151
|
version: '0'
|
149
152
|
requirements: []
|
150
|
-
rubygems_version: 3.0.
|
153
|
+
rubygems_version: 3.0.3
|
151
154
|
signing_key:
|
152
155
|
specification_version: 4
|
153
156
|
summary: Adds newer Ruby methods to older versions.
|