polyfill 1.4.0 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +10 -4
- data/.travis.yml +7 -5
- data/CHANGELOG.md +52 -1
- data/CONTRIBUTING.md +1 -0
- data/README.md +99 -8
- data/lib/polyfill.rb +20 -10
- data/lib/polyfill/internal_utils.rb +23 -7
- data/lib/polyfill/v2_4/regexp.rb +1 -1
- data/lib/polyfill/v2_4/string.rb +1 -1
- data/lib/polyfill/v2_4/symbol.rb +1 -1
- data/lib/polyfill/v2_5.rb +2 -0
- data/lib/polyfill/v2_5/array.rb +13 -0
- data/lib/polyfill/v2_5/set.rb +13 -0
- data/lib/polyfill/v2_6.rb +12 -0
- data/lib/polyfill/v2_6/array.rb +43 -0
- data/lib/polyfill/v2_6/enumerable.rb +29 -0
- data/lib/polyfill/v2_6/hash.rb +65 -0
- data/lib/polyfill/v2_6/kernel.rb +58 -0
- data/lib/polyfill/v2_6/open_struct.rb +31 -0
- data/lib/polyfill/v2_6/string.rb +16 -0
- data/lib/polyfill/v2_6/struct.rb +29 -0
- data/lib/polyfill/version.rb +1 -1
- data/polyfill.gemspec +4 -7
- metadata +23 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96b0596352a22f8cf5311876f9fcf37056e58252fbeddcf85b068b64e32e2e59
|
4
|
+
data.tar.gz: fa748caa7b534b92beb1f02d74e30d734917311cd4d4354381bd62a9bfe93b49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa297f71b043d1456cf28810ebf8daa89745ca035a3b00c315f4097d0dc187500a549754e83fb2ddd36db8f7306837530ccb08ac8dae146f64bb5a3950f8283b
|
7
|
+
data.tar.gz: e3535ed0e215f4afe322636d51d250a5dbfb0d153fd84d32874bc923411465f9590eca111cb0d7f675aecd7b98d6c86aa642661bae85b2346b81828d79ba81b3
|
data/.rubocop.yml
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
AllCops:
|
2
2
|
TargetRubyVersion: 2.1
|
3
|
+
Layout/MultilineMethodCallIndentation:
|
4
|
+
EnforcedStyle: indented
|
3
5
|
Metrics/AbcSize:
|
4
6
|
Enabled: false
|
5
7
|
Metrics/BlockLength:
|
@@ -12,20 +14,22 @@ Metrics/MethodLength:
|
|
12
14
|
Enabled: false
|
13
15
|
Metrics/PerceivedComplexity:
|
14
16
|
Enabled: false
|
17
|
+
Naming/ClassAndModuleCamelCase:
|
18
|
+
Enabled: false
|
19
|
+
Naming/UncommunicativeMethodParamName:
|
20
|
+
Enabled: false
|
21
|
+
Style/AccessModifierDeclarations:
|
22
|
+
Enabled: false
|
15
23
|
Style/AsciiComments:
|
16
24
|
Enabled: false
|
17
25
|
Style/BarePercentLiterals:
|
18
26
|
EnforcedStyle: percent_q
|
19
|
-
Style/ClassAndModuleCamelCase:
|
20
|
-
Enabled: false
|
21
27
|
Style/Documentation:
|
22
28
|
Enabled: false
|
23
29
|
Style/DoubleNegation:
|
24
30
|
Enabled: false
|
25
31
|
Style/FrozenStringLiteralComment:
|
26
32
|
Enabled: false
|
27
|
-
Style/MultilineMethodCallIndentation:
|
28
|
-
EnforcedStyle: indented
|
29
33
|
Style/NumericPredicate:
|
30
34
|
EnforcedStyle: comparison
|
31
35
|
Style/PercentLiteralDelimiters:
|
@@ -33,3 +37,5 @@ Style/PercentLiteralDelimiters:
|
|
33
37
|
'%W': '[]'
|
34
38
|
'%i': '[]'
|
35
39
|
'%w': '[]'
|
40
|
+
Style/YodaCondition:
|
41
|
+
Enabled: false
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,50 @@
|
|
1
|
-
# [1.
|
1
|
+
# [1.9.0][] (2020-12-12)
|
2
|
+
|
3
|
+
## Added
|
4
|
+
|
5
|
+
- Added support for repeatable srb runs from the sorbet gem.
|
6
|
+
|
7
|
+
# [1.8.0][] (2019-09-02)
|
8
|
+
|
9
|
+
## Added
|
10
|
+
|
11
|
+
- v2.6 Kernel#Complex
|
12
|
+
- v2.6 Kernel#Float
|
13
|
+
- v2.6 Kernel#Integer
|
14
|
+
- v2.6 Kernel#Rational
|
15
|
+
- v2.6 Array#to_h
|
16
|
+
- v2.6 Hash#to_h
|
17
|
+
- v2.6 Enumerable#to_h
|
18
|
+
- v2.6 OpenStruct#to_h
|
19
|
+
- v2.6 Struct#to_h
|
20
|
+
|
21
|
+
# [1.7.0][] (2019-02-17)
|
22
|
+
|
23
|
+
## Added
|
24
|
+
|
25
|
+
- v2.6 Array#difference
|
26
|
+
- v2.6 Array#union
|
27
|
+
- v2.6 Hash#merge!
|
28
|
+
- v2.6 Hash#update
|
29
|
+
- v2.6 String#split
|
30
|
+
|
31
|
+
# [1.6.0][] (2019-02-01)
|
32
|
+
|
33
|
+
## Added
|
34
|
+
|
35
|
+
- v2.6 Hash#merge
|
36
|
+
- v2.5 Kernel#then
|
37
|
+
|
38
|
+
# [1.5.0][] (2018-12-30)
|
39
|
+
|
40
|
+
## Added
|
41
|
+
|
42
|
+
- v2.5 Array#append
|
43
|
+
- v2.5 Array#prepend
|
44
|
+
- v2.5 Set#===
|
45
|
+
- v2.5 Set#to_s
|
46
|
+
|
47
|
+
# [1.4.0][] (2018-09-09)
|
2
48
|
|
3
49
|
## Added
|
4
50
|
|
@@ -248,6 +294,11 @@ incorrect type was passed:
|
|
248
294
|
- v2.4 String#concat?
|
249
295
|
- v2.4 String#prepend?
|
250
296
|
|
297
|
+
[1.9.0]: https://github.com/AaronLasseigne/polyfill/compare/v1.8.0...v1.9.0
|
298
|
+
[1.8.0]: https://github.com/AaronLasseigne/polyfill/compare/v1.7.0...v1.8.0
|
299
|
+
[1.7.0]: https://github.com/AaronLasseigne/polyfill/compare/v1.6.0...v1.7.0
|
300
|
+
[1.6.0]: https://github.com/AaronLasseigne/polyfill/compare/v1.5.0...v1.6.0
|
301
|
+
[1.5.0]: https://github.com/AaronLasseigne/polyfill/compare/v1.4.0...v1.5.0
|
251
302
|
[1.4.0]: https://github.com/AaronLasseigne/polyfill/compare/v1.3.0...v1.4.0
|
252
303
|
[1.3.0]: https://github.com/AaronLasseigne/polyfill/compare/v1.2.0...v1.3.0
|
253
304
|
[1.2.0]: https://github.com/AaronLasseigne/polyfill/compare/v1.1.0...v1.2.0
|
data/CONTRIBUTING.md
CHANGED
@@ -9,6 +9,7 @@ please add it to the documentation.
|
|
9
9
|
|
10
10
|
A list of changes can be found at:
|
11
11
|
|
12
|
+
* https://raw.githubusercontent.com/ruby/ruby/v2_6_0/NEWS
|
12
13
|
* https://raw.githubusercontent.com/ruby/ruby/v2_5_0/NEWS
|
13
14
|
* https://raw.githubusercontent.com/ruby/ruby/v2_4_2/NEWS
|
14
15
|
* https://raw.githubusercontent.com/ruby/ruby/v2_3_4/NEWS
|
data/README.md
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# Polyfill
|
2
2
|
|
3
|
-
[![Version](https://
|
4
|
-
[![Build](https://
|
3
|
+
[![Version](https://img.shields.io/gem/v/polyfill.svg?style=flat-square)](https://rubygems.org/gems/polyfill)
|
4
|
+
[![Build](https://img.shields.io/travis/AaronLasseigne/polyfill.svg?style=flat-square)](https://travis-ci.org/AaronLasseigne/polyfill)
|
5
|
+
|
6
|
+
**This gem is no longer supported. I'd recommend exploring [ruby-next](https://github.com/ruby-next/ruby-next) as a replacement.**
|
5
7
|
|
6
8
|
Polyfill implements newer Ruby features into older versions. If the Ruby
|
7
9
|
version already supports the polyfill then calling it does nothing. This is
|
@@ -17,6 +19,7 @@ monkey patching** that may cause issues outside of your use.
|
|
17
19
|
- [Polyfill](#polyfill-1)
|
18
20
|
- [Polyfill.get](#polyfillget)
|
19
21
|
- [Implementation Table](#implementation-table)
|
22
|
+
- [2.6](#26)
|
20
23
|
- [2.5](#25)
|
21
24
|
- [2.4](#24)
|
22
25
|
- [2.3](#23)
|
@@ -27,7 +30,7 @@ monkey patching** that may cause issues outside of your use.
|
|
27
30
|
Add it to your Gemfile:
|
28
31
|
|
29
32
|
```ruby
|
30
|
-
gem 'polyfill', '~> 1.
|
33
|
+
gem 'polyfill', '~> 1.9'
|
31
34
|
```
|
32
35
|
|
33
36
|
Or install it manually:
|
@@ -125,6 +128,95 @@ end
|
|
125
128
|
Partial implemented features will be explained in the "Changes" section of the
|
126
129
|
table. The explanation will follow "**Differences:**".
|
127
130
|
|
131
|
+
### 2.6
|
132
|
+
|
133
|
+
| | Object | Method | Changes |
|
134
|
+
|:-:| ---------------- | -------------------------- | ------- |
|
135
|
+
| ✓ | Array | #difference | New
|
136
|
+
| ✗ | | #filter | New (alias of `select`)
|
137
|
+
| ✗ | | #filter! | New (alias of `select!`)
|
138
|
+
| ✓ | | #to_h | Accepts a block that maps elements to new key/value pairs.
|
139
|
+
| ✓ | | #union | New
|
140
|
+
| ✗ | Binding | #source_location | New
|
141
|
+
| ✗ | Coverage | .line_stub | New
|
142
|
+
| ✗ | | .result | Accepts new optional keyword arguments, `:clear` and `:stop`.
|
143
|
+
| ✗ | | .start | Accepts a new optional keyword argument, `:oneshot_line`.
|
144
|
+
| ✗ | Dir | #children | New
|
145
|
+
| ✗ | | #each_child | New
|
146
|
+
| ✗ | Enumerable | #+ | New
|
147
|
+
| ✗ | | #chain | New
|
148
|
+
| ✗ | | #filter | New (alias of `select`)
|
149
|
+
| ✓ | | #to_h | Accepts a block that maps elements to new key/value pairs.
|
150
|
+
| ✗ | Enumerator::Lazy | #filter | New (alias of `select`)
|
151
|
+
| ✗ | ENV | #to_h | Accepts a block that maps elements to new key/value pairs.
|
152
|
+
| ✗ | ERB | .new | Accepts new optional keyword arguments, `:eoutvar` and `:trim_mode`.
|
153
|
+
| ✗ | Exception | #full_message | Accepts new optional keyword arguments, `:highlight` and `:order`.
|
154
|
+
| ✗ | File | .binread | Does not invoke external commands even if the path starts with `\|`.
|
155
|
+
| ✗ | | .binwrite | Does not invoke external commands even if the path starts with `\|`.
|
156
|
+
| ✗ | | .foreach | Does not invoke external commands even if the path starts with `\|`.
|
157
|
+
| ✗ | | .read | Does not invoke external commands even if the path starts with `\|`.
|
158
|
+
| ✗ | | .readlines | Does not invoke external commands even if the path starts with `\|`.
|
159
|
+
| ✗ | | .write | Does not invoke external commands even if the path starts with `\|`.
|
160
|
+
| ✗ | FileUtils | #cp_lr | New
|
161
|
+
| ✗ | Hash | #filter | New (alias of `select`)
|
162
|
+
| ✗ | | #filter! | New (alias of `select!`)
|
163
|
+
| ✓ | | #merge | Accepts multiple arguments.
|
164
|
+
| ✓ | | #merge! | Accepts multiple arguments.
|
165
|
+
| ✓ | | #to_h | Accepts a block that maps elements to new key/value pairs.
|
166
|
+
| ✓ | | #update | Accepts multiple arguments.
|
167
|
+
| ✗ | Kernel | #BigDecimal | Accepts a new optional keyword argument, `:exception`.
|
168
|
+
| ✓ | | #Complex | Accepts a new optional keyword argument, `:exception`.
|
169
|
+
| ✗ | | #exec | Does not close non-standard file descriptors.
|
170
|
+
| ✓ | | #Float | Accepts a new optional keyword argument, `:exception`.
|
171
|
+
| ✓ | | #Integer | Accepts a new optional keyword argument, `:exception`.
|
172
|
+
| ✓ | | #Rational | Accepts a new optional keyword argument, `:exception`.
|
173
|
+
| ✓ | | #then | New (alias of `yield_self`)
|
174
|
+
| ✗ | | #system | Accepts a new optional keyword argument, `:exception`. Does not close non-standard file descriptors.
|
175
|
+
| ✗ | KeyError | .new | Accepts new optional keyword arguments, `:receiver` and `:key`.
|
176
|
+
| ✗ | Matrix | #[]= | New
|
177
|
+
| ✗ | | #antisymmetric? | New
|
178
|
+
| ✗ | | #collect! | New
|
179
|
+
| ✗ | | #map! | New
|
180
|
+
| ✗ | | #skew_symmetric? | New
|
181
|
+
| ✗ | Method | #<< | New
|
182
|
+
| ✗ | | #>> | New
|
183
|
+
| ✗ | Module | #method_defined? | Accepts a second optional argument (default: `true`). If `false`, it only checks the class and not the ancestors.
|
184
|
+
| ✗ | | #private_method_defined? | Accepts a second optional argument (default: `true`). If `false`, it only checks the class and not the ancestors.
|
185
|
+
| ✗ | | #protected_method_defined? | Accepts a second optional argument (default: `true`). If `false`, it only checks the class and not the ancestors.
|
186
|
+
| ✗ | NameError | .new | Accepts new optional keyword arguments, `:receiver` and `:key`.
|
187
|
+
| ✗ | Net::HTTP | .new | Accepts a new optional keyword argument, `:write_timeout`.
|
188
|
+
| ✗ | | #write_timeout | New
|
189
|
+
| ✗ | | #write_timeout= | New
|
190
|
+
| ✗ | NilClass | #=~ | New
|
191
|
+
| ✗ | NoMethodError | .new | Accepts new optional keyword arguments, `:receiver` and `:key`.
|
192
|
+
| ✗ | Numeric | #step | Now returns an instance of the Enumerator::ArithmeticSequence class rather than one of the Enumerator class.
|
193
|
+
| ✓ | OpenStruct | #to_h | Accepts a block that maps keys and values to new keys and values.
|
194
|
+
| ✗ | Proc | #<< | New
|
195
|
+
| ✗ | | #>> | New
|
196
|
+
| ✗ | | .call | No longer changes `$SAFE`.
|
197
|
+
| ✗ | Random | .bytes | New
|
198
|
+
| ✗ | Range | #% | New
|
199
|
+
| ✗ | | #=== | Now uses `cover?` instead of `include?`.
|
200
|
+
| ✗ | | #cover? | Accepts a Range.
|
201
|
+
| ✗ | | #step | Now returns an instance of the Enumerator::ArithmeticSequence class rather than one of the Enumerator class.
|
202
|
+
| ✗ | RSS::Parser | .parse | Accepts options as a Hash. Options are `:ignore_unknown_element`, `:parser_class`, and `:validate`.
|
203
|
+
| ✗ | Set | #filter! | New (alias of `select!`)
|
204
|
+
| ✓ | String | #split | Yields each substring to a block if given.
|
205
|
+
| ✗ | Struct | #filter | New (alias of `select`)
|
206
|
+
| ✓ | | #to_h | Accepts a block that maps keys and values to new keys and values.
|
207
|
+
| ✗ | Time | #+ | Preserves the timezone.
|
208
|
+
| ✗ | | #- | Preserves the timezone.
|
209
|
+
| ✗ | | .new | Accepts a timezone object as well as a UTC offset string.
|
210
|
+
| ✗ | | #getlocal | Accepts a timezone object as well as a UTC offset string.
|
211
|
+
| ✗ | | #succ | Preserves the timezone.
|
212
|
+
| ✗ | TracePoint | #enable | Accepts new optional keyword arguments, `:target` and `:target_line`.
|
213
|
+
| ✗ | | #eval_script | New
|
214
|
+
| ✗ | | #instruction_sequence | New
|
215
|
+
| ✗ | | #parameters | New
|
216
|
+
| ✗ | Vector | #[]= | New
|
217
|
+
| ✗ | | #collect! | New
|
218
|
+
| ✗ | | #map! | New
|
219
|
+
|
128
220
|
### 2.5
|
129
221
|
|
130
222
|
Attempting to modify frozen objects now throws `FrozenError` instead of
|
@@ -134,8 +226,8 @@ though they have techically changed. `FrozenError` is a subclass of
|
|
134
226
|
|
135
227
|
| | Object | Method | Changes |
|
136
228
|
|:-:| ---------------- | ------------------------ | ------- |
|
137
|
-
|
|
138
|
-
|
|
229
|
+
| ✓ | Array | #append | New (alias for `push`)
|
230
|
+
| ✓ | | #prepend | New (alias for `unshift`)
|
139
231
|
| ✓ | BigDecimal | #clone | Returns the receiver itself instead of making a new instance.
|
140
232
|
| ✓ | | #dup | Returns the receiver itself instead of making a new instance.
|
141
233
|
| ✓ | Dir | .children | New
|
@@ -210,9 +302,9 @@ though they have techically changed. `FrozenError` is a subclass of
|
|
210
302
|
| ✗ | Range | .initialize | No longer hides exceptions when comparing begin and end with `<=>` and raise a "bad value for range" `ArgumentError` but instead lets the exception from the `<=>` call go through.
|
211
303
|
| ✗ | Random | #urandom | Renamed from `raw_seed`.
|
212
304
|
| ✗ | SecureRandom | .alphanumeric | New
|
213
|
-
|
|
305
|
+
| ✓ | Set | #=== | New (alias of `include?`)
|
214
306
|
| ✗ | | #reset | New
|
215
|
-
|
|
307
|
+
| ✓ | | #to_s | New (alias of `inspect`)
|
216
308
|
| ✓ | String | #casecmp | Returns `nil` for non-string arguments instead of raising a `TypeError`.
|
217
309
|
| ✓ | | #casecmp? | Returns `nil` for non-string arguments instead of raising a `TypeError`.
|
218
310
|
| ✓ | | #delete_prefix | New
|
@@ -395,7 +487,6 @@ though they have techically changed. `FrozenError` is a subclass of
|
|
395
487
|
| ✓ | Numeric | #negative? | New
|
396
488
|
| ✓ | | #positive? | New
|
397
489
|
| ✗ | Object | #define_singleton_method | Now requires a method body, `Proc`, `Method`, or a block.
|
398
|
-
| ✗ | | #timeout | Warns that it is deprecated.
|
399
490
|
| ✗ | ObjectSpace | .count_symbols | New
|
400
491
|
| ✗ | | .count_imemo_objects | New
|
401
492
|
| ✗ | | .internal_class_of | New
|
data/lib/polyfill.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require_relative 'polyfill/version'
|
2
|
+
require_relative 'polyfill/internal_utils'
|
3
3
|
|
4
4
|
module Polyfill
|
5
5
|
module Module; end
|
@@ -9,10 +9,12 @@ module Polyfill
|
|
9
9
|
raise ArgumentError, "#{module_name} is a class not a module"
|
10
10
|
end
|
11
11
|
|
12
|
+
version_option = options.delete(:version)
|
13
|
+
|
12
14
|
#
|
13
15
|
# parse options
|
14
16
|
#
|
15
|
-
versions = InternalUtils.polyfill_versions_to_use(
|
17
|
+
versions = InternalUtils.polyfill_versions_to_use(version_option)
|
16
18
|
|
17
19
|
unless options.empty?
|
18
20
|
raise ArgumentError, "unknown keyword: #{options.first[0]}"
|
@@ -35,7 +37,7 @@ module Polyfill
|
|
35
37
|
#
|
36
38
|
# build the module to return
|
37
39
|
#
|
38
|
-
InternalUtils.create_module do |mod|
|
40
|
+
InternalUtils.create_module(module_name, methods, options, version_option) do |mod|
|
39
41
|
# make sure the methods get added if this module is included
|
40
42
|
mod.singleton_class.send(:define_method, :included) do |base|
|
41
43
|
modules.each do |module_to_add|
|
@@ -61,7 +63,7 @@ module Polyfill
|
|
61
63
|
module_function :get
|
62
64
|
end
|
63
65
|
|
64
|
-
def Polyfill(options = {}) # rubocop:disable
|
66
|
+
def Polyfill(options = {}) # rubocop:disable Naming/MethodName
|
65
67
|
#
|
66
68
|
# parse options
|
67
69
|
#
|
@@ -90,7 +92,7 @@ def Polyfill(options = {}) # rubocop:disable Style/MethodName
|
|
90
92
|
#
|
91
93
|
# build the module to return
|
92
94
|
#
|
93
|
-
Polyfill::InternalUtils.create_module do |mod|
|
95
|
+
Polyfill::InternalUtils.create_module(options) do |mod|
|
94
96
|
objects.each do |object_name, methods|
|
95
97
|
#
|
96
98
|
# find all polyfills for the object across all versions
|
@@ -203,6 +205,13 @@ def Polyfill(options = {}) # rubocop:disable Style/MethodName
|
|
203
205
|
refine Object.const_get(klass, false) do
|
204
206
|
include instance_module
|
205
207
|
|
208
|
+
# Certain Kernel methods are private outside of Kernel
|
209
|
+
if klass == 'Object'
|
210
|
+
%i[Complex Float Integer Rational].each do |method|
|
211
|
+
private method if methods_added.include?(method)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
206
215
|
if native
|
207
216
|
Polyfill::InternalUtils.ignore_warnings do
|
208
217
|
define_method :respond_to? do |name, include_all = false|
|
@@ -227,7 +236,8 @@ def Polyfill(options = {}) # rubocop:disable Style/MethodName
|
|
227
236
|
end
|
228
237
|
end
|
229
238
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
239
|
+
require_relative 'polyfill/v2_2'
|
240
|
+
require_relative 'polyfill/v2_3'
|
241
|
+
require_relative 'polyfill/v2_4'
|
242
|
+
require_relative 'polyfill/v2_5'
|
243
|
+
require_relative 'polyfill/v2_6'
|
@@ -4,7 +4,8 @@ module Polyfill
|
|
4
4
|
'2.2' => 'V2_2',
|
5
5
|
'2.3' => 'V2_3',
|
6
6
|
'2.4' => 'V2_4',
|
7
|
-
'2.5' => 'V2_5'
|
7
|
+
'2.5' => 'V2_5',
|
8
|
+
'2.6' => 'V2_6'
|
8
9
|
}.freeze
|
9
10
|
private_constant :VERSIONS
|
10
11
|
|
@@ -26,7 +27,7 @@ module Polyfill
|
|
26
27
|
def polyfill_versions_to_use(desired_version = nil)
|
27
28
|
desired_version = VERSIONS.keys.max if desired_version.nil?
|
28
29
|
|
29
|
-
unless VERSIONS.
|
30
|
+
unless VERSIONS.key?(desired_version)
|
30
31
|
raise ArgumentError, "invalid value for keyword version: #{desired_version}"
|
31
32
|
end
|
32
33
|
|
@@ -82,15 +83,30 @@ module Polyfill
|
|
82
83
|
end
|
83
84
|
module_function :methods_to_keep
|
84
85
|
|
85
|
-
def create_module
|
86
|
-
|
86
|
+
def create_module(*args)
|
87
|
+
module_name = namify_arguments(*args)
|
87
88
|
|
88
|
-
|
89
|
-
|
90
|
-
|
89
|
+
if ::Polyfill::Module.const_defined?(module_name, false)
|
90
|
+
::Polyfill::Module.const_get(module_name, false)
|
91
|
+
else
|
92
|
+
mod = ::Module.new
|
93
|
+
yield(mod)
|
94
|
+
::Polyfill::Module.const_set(module_name, mod)
|
95
|
+
end
|
91
96
|
end
|
92
97
|
module_function :create_module
|
93
98
|
|
99
|
+
def namify_arguments(*args)
|
100
|
+
string = args.map(&:inspect).join
|
101
|
+
# we don't need this to be decodable,
|
102
|
+
# we just need a consistent class-nameable output for a consistent arbitrary input
|
103
|
+
# safest module name is: start with capital then, A-Za-z0-9_
|
104
|
+
encoded = [string].pack('m0')
|
105
|
+
.gsub(%r{[+/=]}, '+' => '_1', '/' => '_2', '=' => '_')
|
106
|
+
"M#{encoded}"
|
107
|
+
end
|
108
|
+
module_function :namify_arguments
|
109
|
+
|
94
110
|
def to_str(obj)
|
95
111
|
begin
|
96
112
|
unless obj.respond_to?(:to_str)
|
data/lib/polyfill/v2_4/regexp.rb
CHANGED
data/lib/polyfill/v2_4/string.rb
CHANGED
data/lib/polyfill/v2_4/symbol.rb
CHANGED
data/lib/polyfill/v2_5.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require_relative 'v2_5/array'
|
1
2
|
require_relative 'v2_5/dir'
|
2
3
|
require_relative 'v2_5/enumerable'
|
3
4
|
require_relative 'v2_5/hash'
|
@@ -8,6 +9,7 @@ require_relative 'v2_5/struct'
|
|
8
9
|
require_relative 'v2_5/time'
|
9
10
|
|
10
11
|
require_relative 'v2_5/big_decimal'
|
12
|
+
require_relative 'v2_5/set'
|
11
13
|
|
12
14
|
module Polyfill
|
13
15
|
module V2_5
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require_relative 'v2_6/array'
|
2
|
+
require_relative 'v2_6/enumerable'
|
3
|
+
require_relative 'v2_6/hash'
|
4
|
+
require_relative 'v2_6/kernel'
|
5
|
+
require_relative 'v2_6/open_struct'
|
6
|
+
require_relative 'v2_6/string'
|
7
|
+
require_relative 'v2_6/struct'
|
8
|
+
|
9
|
+
module Polyfill
|
10
|
+
module V2_6
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Polyfill
|
2
|
+
module V2_6
|
3
|
+
module Array
|
4
|
+
def difference(*arrays)
|
5
|
+
arrays.reduce([*self]) do |me, array|
|
6
|
+
me - array
|
7
|
+
end
|
8
|
+
end
|
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
|
+
|
34
|
+
def union(*arrays)
|
35
|
+
return self | [] if arrays.empty?
|
36
|
+
|
37
|
+
arrays.reduce(self) do |me, array|
|
38
|
+
me | array
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -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
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Polyfill
|
2
|
+
module V2_6
|
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
|
+
|
28
|
+
def merge(*args)
|
29
|
+
if block_given?
|
30
|
+
args.each_with_object(dup) do |arg, h|
|
31
|
+
h.merge!(arg, &::Proc.new)
|
32
|
+
end
|
33
|
+
else
|
34
|
+
args.each_with_object(dup) do |arg, h|
|
35
|
+
h.merge!(arg)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def merge!(*args)
|
41
|
+
if block_given?
|
42
|
+
args.each_with_object(self) do |arg, h|
|
43
|
+
h.merge!(arg, &::Proc.new)
|
44
|
+
end
|
45
|
+
else
|
46
|
+
args.each_with_object(self) do |arg, h|
|
47
|
+
h.merge!(arg)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def update(*args)
|
53
|
+
if block_given?
|
54
|
+
args.each_with_object(self) do |arg, h|
|
55
|
+
h.update(arg, &::Proc.new)
|
56
|
+
end
|
57
|
+
else
|
58
|
+
args.each_with_object(self) do |arg, h|
|
59
|
+
h.update(arg)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Polyfill
|
2
|
+
module V2_6
|
3
|
+
module Kernel
|
4
|
+
using Polyfill(Kernel: %w[#yield_self], version: '2.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
|
+
|
51
|
+
def then
|
52
|
+
return yield_self unless block_given?
|
53
|
+
|
54
|
+
yield_self(&::Proc.new)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -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
data/polyfill.gemspec
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
lib = File.expand_path('../lib', __FILE__)
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
4
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
3
|
require 'polyfill/version'
|
6
4
|
|
@@ -23,8 +21,7 @@ Gem::Specification.new do |spec|
|
|
23
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
22
|
spec.require_paths = ['lib']
|
25
23
|
|
26
|
-
spec.add_development_dependency '
|
27
|
-
spec.add_development_dependency '
|
28
|
-
spec.add_development_dependency '
|
29
|
-
spec.add_development_dependency 'rubocop', '~> 0.48.1'
|
24
|
+
spec.add_development_dependency 'rake', '~> 12.3'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.8'
|
26
|
+
spec.add_development_dependency 'rubocop', '~> 0.57.0' # highest supporting 2.1
|
30
27
|
end
|
metadata
CHANGED
@@ -1,72 +1,58 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polyfill
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Lasseigne
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: bundler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.14'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.14'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: rake
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
17
|
- - "~>"
|
32
18
|
- !ruby/object:Gem::Version
|
33
|
-
version: '12.
|
19
|
+
version: '12.3'
|
34
20
|
type: :development
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
24
|
- - "~>"
|
39
25
|
- !ruby/object:Gem::Version
|
40
|
-
version: '12.
|
26
|
+
version: '12.3'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: rspec
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
31
|
- - "~>"
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version: '3.
|
33
|
+
version: '3.8'
|
48
34
|
type: :development
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
38
|
- - "~>"
|
53
39
|
- !ruby/object:Gem::Version
|
54
|
-
version: '3.
|
40
|
+
version: '3.8'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: rubocop
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
45
|
- - "~>"
|
60
46
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.
|
47
|
+
version: 0.57.0
|
62
48
|
type: :development
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
52
|
- - "~>"
|
67
53
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.
|
69
|
-
description:
|
54
|
+
version: 0.57.0
|
55
|
+
description:
|
70
56
|
email:
|
71
57
|
- aaron.lasseigne@gmail.com
|
72
58
|
executables: []
|
@@ -124,22 +110,32 @@ files:
|
|
124
110
|
- lib/polyfill/v2_4/string_io.rb
|
125
111
|
- lib/polyfill/v2_4/symbol.rb
|
126
112
|
- lib/polyfill/v2_5.rb
|
113
|
+
- lib/polyfill/v2_5/array.rb
|
127
114
|
- lib/polyfill/v2_5/big_decimal.rb
|
128
115
|
- lib/polyfill/v2_5/dir.rb
|
129
116
|
- lib/polyfill/v2_5/enumerable.rb
|
130
117
|
- lib/polyfill/v2_5/hash.rb
|
131
118
|
- lib/polyfill/v2_5/integer.rb
|
132
119
|
- lib/polyfill/v2_5/kernel.rb
|
120
|
+
- lib/polyfill/v2_5/set.rb
|
133
121
|
- lib/polyfill/v2_5/string.rb
|
134
122
|
- lib/polyfill/v2_5/struct.rb
|
135
123
|
- lib/polyfill/v2_5/time.rb
|
124
|
+
- lib/polyfill/v2_6.rb
|
125
|
+
- lib/polyfill/v2_6/array.rb
|
126
|
+
- lib/polyfill/v2_6/enumerable.rb
|
127
|
+
- lib/polyfill/v2_6/hash.rb
|
128
|
+
- lib/polyfill/v2_6/kernel.rb
|
129
|
+
- lib/polyfill/v2_6/open_struct.rb
|
130
|
+
- lib/polyfill/v2_6/string.rb
|
131
|
+
- lib/polyfill/v2_6/struct.rb
|
136
132
|
- lib/polyfill/version.rb
|
137
133
|
- polyfill.gemspec
|
138
134
|
homepage: ''
|
139
135
|
licenses:
|
140
136
|
- MIT
|
141
137
|
metadata: {}
|
142
|
-
post_install_message:
|
138
|
+
post_install_message:
|
143
139
|
rdoc_options: []
|
144
140
|
require_paths:
|
145
141
|
- lib
|
@@ -154,9 +150,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
150
|
- !ruby/object:Gem::Version
|
155
151
|
version: '0'
|
156
152
|
requirements: []
|
157
|
-
|
158
|
-
|
159
|
-
signing_key:
|
153
|
+
rubygems_version: 3.1.4
|
154
|
+
signing_key:
|
160
155
|
specification_version: 4
|
161
156
|
summary: Adds newer Ruby methods to older versions.
|
162
157
|
test_files: []
|