polyfill 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -1
- data/CONTRIBUTING.md +11 -0
- data/README.md +73 -33
- data/lib/polyfill.rb +74 -61
- data/lib/polyfill/v2_3.rb +8 -0
- data/lib/polyfill/v2_3/array.rb +9 -0
- data/lib/polyfill/v2_3/array/instance.rb +11 -0
- data/lib/polyfill/v2_3/array/instance/dig.rb +42 -0
- data/lib/polyfill/v2_3/enumerable/instance.rb +4 -0
- data/lib/polyfill/v2_3/enumerable/instance/chunk_while.rb +2 -2
- data/lib/polyfill/v2_3/enumerable/instance/grep_v.rb +48 -0
- data/lib/polyfill/v2_3/enumerable/instance/slice_before.rb +48 -0
- data/lib/polyfill/v2_3/enumerator/lazy.rb +11 -0
- data/lib/polyfill/v2_3/enumerator/lazy/instance.rb +13 -0
- data/lib/polyfill/v2_3/enumerator/lazy/instance/grep_v.rb +31 -0
- data/lib/polyfill/v2_3/hash.rb +9 -0
- data/lib/polyfill/v2_3/hash/instance.rb +15 -0
- data/lib/polyfill/v2_3/hash/instance/dig.rb +17 -0
- data/lib/polyfill/v2_3/hash/instance/fetch_values.rb +32 -0
- data/lib/polyfill/v2_3/hash/instance/to_proc.rb +23 -0
- data/lib/polyfill/v2_3/string.rb +2 -0
- data/lib/polyfill/v2_3/string/instance.rb +13 -0
- data/lib/polyfill/v2_3/string/instance/minus_unary.rb +23 -0
- data/lib/polyfill/v2_3/string/instance/plus_unary.rb +23 -0
- data/lib/polyfill/v2_3/struct.rb +9 -0
- data/lib/polyfill/v2_3/struct/instance.rb +11 -0
- data/lib/polyfill/v2_3/struct/instance/dig.rb +17 -0
- data/lib/polyfill/v2_4/enumerable/instance/uniq.rb +1 -1
- data/lib/polyfill/v2_4/io/class/foreach.rb +1 -1
- data/lib/polyfill/v2_4/io/instance/each_line.rb +1 -1
- data/lib/polyfill/v2_4/io/instance/lines.rb +1 -1
- data/lib/polyfill/v2_4/string/instance/lines.rb +1 -1
- data/lib/polyfill/v2_4/symbol/instance/match.rb +1 -1
- data/lib/polyfill/version.rb +1 -1
- metadata +21 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 378610a792ea5873a656859b5e1bd5d46402dd70
|
4
|
+
data.tar.gz: d0d81f15485b7bc5de7f0480071aa32d90f583f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9a61e5c76de85f31c9ee24ec75e125102b78acd7ed235e1227c55e3792bacb6bf991eadc90f2695141e3978abdd8ce4720d00e137bf0a7e20197ae213e7ea7b
|
7
|
+
data.tar.gz: f3b1f7bfd59f1fd341c061a05ce48804db9e933db5b8bad4e664473bcaf586a37cb1bb84e63c4f55dd60fde0271f2d57aa64362723263539327f3c9adac5ea51
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,28 @@
|
|
1
|
+
# [0.6.0][] (2017-04-06)
|
2
|
+
|
3
|
+
## Fix
|
4
|
+
|
5
|
+
- You can now use the `:version` option with no other specification
|
6
|
+
|
7
|
+
## Added
|
8
|
+
|
9
|
+
- v2.3 Array#dig
|
10
|
+
- v2.3 Enumerable#grep_v
|
11
|
+
- v2.3 Enumerable#slice_before
|
12
|
+
- v2.3 Enumerator::Lazy#grep_v
|
13
|
+
- v2.3 Hash#dig
|
14
|
+
- v2.3 Hash#fetch_values
|
15
|
+
- v2.3 Hash#to_proc
|
16
|
+
- v2.3 String#+@
|
17
|
+
- v2.3 String#-@
|
18
|
+
- v2.3 Struct#dig
|
19
|
+
|
1
20
|
# [0.5.0][] (2017-03-26)
|
2
21
|
|
3
22
|
## Added
|
23
|
+
|
4
24
|
- Support for Ruby 2.2
|
5
|
-
-
|
25
|
+
- `:version` option to limit the max acceptable version for changes
|
6
26
|
- v2.3 String.new
|
7
27
|
- v2.3 Enumerable#chunk_while
|
8
28
|
|
data/CONTRIBUTING.md
CHANGED
@@ -7,6 +7,16 @@ please add it to the documentation.
|
|
7
7
|
|
8
8
|
### Code
|
9
9
|
|
10
|
+
A list of changes can be found at:
|
11
|
+
|
12
|
+
* https://raw.githubusercontent.com/ruby/ruby/v2_4_1/NEWS
|
13
|
+
* https://raw.githubusercontent.com/ruby/ruby/v2_3_4/NEWS
|
14
|
+
* https://raw.githubusercontent.com/ruby/ruby/v2_2_7/NEWS
|
15
|
+
* https://raw.githubusercontent.com/ruby/ruby/v2_1_10/NEWS
|
16
|
+
* https://raw.githubusercontent.com/ruby/ruby/v2_0_0_648/NEWS
|
17
|
+
|
18
|
+
Specific changes can be found by going to the [Ruby bug/feature tracker].
|
19
|
+
|
10
20
|
These are the steps that you'll need to follow for submitting code:
|
11
21
|
|
12
22
|
1. [Fork](#fork)
|
@@ -88,3 +98,4 @@ eyes catch more issues. After everything is fixed: VICTORY!
|
|
88
98
|
[documentation]: README.md
|
89
99
|
[Fork]: https://github.com/AaronLasseigne/polyfill/fork
|
90
100
|
[Ruby Spec Suite]: https://github.com/ruby/spec
|
101
|
+
[Ruby bug/feature tracker]: https://bugs.ruby-lang.org
|
data/README.md
CHANGED
@@ -34,7 +34,7 @@ See the [implementation table](#implementation-table) for specifics about what h
|
|
34
34
|
Add it to your Gemfile:
|
35
35
|
|
36
36
|
```ruby
|
37
|
-
gem 'polyfill', '0.
|
37
|
+
gem 'polyfill', '0.6.0'
|
38
38
|
```
|
39
39
|
|
40
40
|
Or install it manually:
|
@@ -206,38 +206,78 @@ end
|
|
206
206
|
|
207
207
|
### 2.2 to 2.3
|
208
208
|
|
209
|
-
| Object
|
210
|
-
|
|
211
|
-
| ARGF
|
212
|
-
| Array
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
| |
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
209
|
+
| Object | Method | Implemented | Notes |
|
210
|
+
| ----------------------- | ------------------------ | ----------- | ----- |
|
211
|
+
| ARGF | #read_nonblock | No |
|
212
|
+
| Array | #bsearch_index | No |
|
213
|
+
| | #dig | Yes |
|
214
|
+
| | #flatten | No |
|
215
|
+
| | #flatten! | No |
|
216
|
+
| | #inspect | No |
|
217
|
+
| | #pack | No |
|
218
|
+
| Base64 | .urlsafe_encode64 | No |
|
219
|
+
| | .urlsafe_decode64 | No |
|
220
|
+
| BasicSocket | #recv | No |
|
221
|
+
| | #recv_nonblock | No |
|
222
|
+
| | #recvmsg_nonblock | No |
|
223
|
+
| | #sendmsg_nonblock | No |
|
224
|
+
| Comparable | #== | No |
|
225
|
+
| Coverage | .peek_result | No |
|
226
|
+
| Enumerable | #chunk | No |
|
227
|
+
| | #chunk_while | Yes |
|
228
|
+
| | #grep_v | Yes |
|
229
|
+
| | #slice_before | Yes |
|
230
|
+
| Enumerator::Lazy | #grep_v | Yes |
|
231
|
+
| File | .mkfifo | No |
|
232
|
+
| File::Stat | #ino | No |
|
233
|
+
| Hash | #< | No |
|
234
|
+
| | #<= | No |
|
235
|
+
| | #> | No |
|
236
|
+
| | #>= | No |
|
237
|
+
| | #dig | Yes |
|
238
|
+
| | #fetch_values | Yes |
|
239
|
+
| | #inspect | No |
|
240
|
+
| | #to_proc | Partial | Works in every respect but returns a `lambda` instead of a `proc`. Returning a `proc` may be an error in MRI's implementation. See: https://bugs.ruby-lang.org/issues/12671
|
241
|
+
| IO | #advise | No |
|
242
|
+
| | #close | No |
|
243
|
+
| | #each_codepoint | No |
|
244
|
+
| | #wait_readable | No |
|
245
|
+
| Kernel | #loop | No |
|
246
|
+
| Logger | #level= | No |
|
247
|
+
| | #reopen | No |
|
248
|
+
| Module | #define_method | No |
|
249
|
+
| | #deprecate_constant | No |
|
250
|
+
| NameError | #receiver | No |
|
251
|
+
| Net::FTP | .default_passive= | No |
|
252
|
+
| | #mlst | No |
|
253
|
+
| | #mlsd | No |
|
254
|
+
| Net::HTTP | #open_timeout | No |
|
255
|
+
| Numeric | #negative? | No |
|
256
|
+
| | #positive? | No |
|
257
|
+
| Object | #define_singleton_method | No |
|
258
|
+
| | #timeout | No |
|
259
|
+
| ObjectSpace | .count_symbols | No |
|
260
|
+
| | .count_imemo_objects | No |
|
261
|
+
| | .internal_class_of | No |
|
262
|
+
| | .internal_super_of | No |
|
263
|
+
| OpenSSL::SSL::SSLSocket | #accept_nonblock | No |
|
264
|
+
| | #connect_nonblock | No |
|
265
|
+
| Pathname | #ascend | No |
|
266
|
+
| | #descend | No |
|
267
|
+
| Queue | #close | No |
|
268
|
+
| Socket | #accept_nonblock | No |
|
269
|
+
| | #connect_nonblock | No |
|
270
|
+
| String | #+@ | Yes |
|
271
|
+
| | #-@ | Yes |
|
272
|
+
| | .new | Yes |
|
273
|
+
| | #unpack | No |
|
274
|
+
| StringIO | #set_encoding | No |
|
275
|
+
| Struct | #dig | Yes |
|
276
|
+
| TCPServer | #accept_nonblock | No |
|
277
|
+
| Thread | #name | No |
|
278
|
+
| | #name= | No |
|
279
|
+
| UNIXServer | #accept_nonblock | No |
|
280
|
+
| Vector | #round | No |
|
241
281
|
|
242
282
|
## Contributing
|
243
283
|
|
data/lib/polyfill.rb
CHANGED
@@ -6,6 +6,8 @@ require 'polyfill/v2_4'
|
|
6
6
|
module Polyfill
|
7
7
|
include V2_3
|
8
8
|
include V2_4
|
9
|
+
|
10
|
+
module Parcel; end
|
9
11
|
end
|
10
12
|
|
11
13
|
def Polyfill(options) # rubocop:disable Style/MethodName
|
@@ -32,80 +34,91 @@ def Polyfill(options) # rubocop:disable Style/MethodName
|
|
32
34
|
|
33
35
|
current_ruby_version = RUBY_VERSION[/\A(\d+\.\d+)/, 1]
|
34
36
|
|
35
|
-
objects.
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
.map do |version_number, version_module|
|
40
|
-
begin
|
41
|
-
final_module = object_module_names
|
42
|
-
.reduce(version_module) do |current_mod, name|
|
43
|
-
current_mod.const_get(name, false)
|
44
|
-
end
|
45
|
-
|
46
|
-
[version_number, final_module]
|
47
|
-
rescue NameError
|
48
|
-
nil
|
49
|
-
end
|
37
|
+
if objects.empty?
|
38
|
+
mod.module_eval do
|
39
|
+
versions.each do |_, object_module|
|
40
|
+
include object_module
|
50
41
|
end
|
51
|
-
.compact
|
52
|
-
|
53
|
-
if object_modules.empty?
|
54
|
-
raise ArgumentError, %Q("#{full_name}" is not a valid class or has no updates)
|
55
42
|
end
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
43
|
+
else
|
44
|
+
objects.each do |full_name, methods|
|
45
|
+
object_module_names = full_name.to_s.split('::')
|
46
|
+
|
47
|
+
object_modules = versions
|
48
|
+
.map do |version_number, version_module|
|
49
|
+
begin
|
50
|
+
final_module = object_module_names
|
51
|
+
.reduce(version_module) do |current_mod, name|
|
52
|
+
current_mod.const_get(name, false)
|
53
|
+
end
|
54
|
+
|
55
|
+
[version_number, final_module]
|
56
|
+
rescue NameError
|
57
|
+
nil
|
58
|
+
end
|
61
59
|
end
|
60
|
+
.compact
|
61
|
+
|
62
|
+
if object_modules.empty?
|
63
|
+
raise ArgumentError, %Q("#{full_name}" is not a valid class or has no updates)
|
62
64
|
end
|
63
|
-
|
64
|
-
methods
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
:Class
|
69
|
-
when '#'
|
70
|
-
:Instance
|
71
|
-
else
|
72
|
-
raise ArgumentError, %Q("#{method}" must start with a "." if it's a class method or "#" if it's an instance method)
|
65
|
+
|
66
|
+
if methods == :all
|
67
|
+
mod.module_eval do
|
68
|
+
object_modules.each do |version_number, object_module|
|
69
|
+
include object_module if version_number > current_ruby_version
|
73
70
|
end
|
71
|
+
end
|
72
|
+
else
|
73
|
+
methods.each do |method|
|
74
|
+
type =
|
75
|
+
case method[0]
|
76
|
+
when '.'
|
77
|
+
:Class
|
78
|
+
when '#'
|
79
|
+
:Instance
|
80
|
+
else
|
81
|
+
raise ArgumentError, %Q("#{method}" must start with a "." if it's a class method or "#" if it's an instance method)
|
82
|
+
end
|
74
83
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
.
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
84
|
+
method_name = method[1..-1]
|
85
|
+
symbol_conversions = {
|
86
|
+
'-' => 'minus', # must come first otherwise it creates a range in the regexp
|
87
|
+
'+' => 'plus',
|
88
|
+
'@' => '_unary',
|
89
|
+
'=' => 'equal',
|
90
|
+
'<' => 'lessthan',
|
91
|
+
'>' => 'greaterthan',
|
92
|
+
'?' => '_q',
|
93
|
+
'!' => '_e'
|
94
|
+
}
|
95
|
+
method_name.gsub!(/[#{symbol_conversions.keys.join}]/o, symbol_conversions)
|
96
|
+
method_name.capitalize!
|
97
|
+
method_name.gsub!(/_(.)/) { |match| match[1].capitalize }
|
98
|
+
|
99
|
+
method_modules = object_modules
|
100
|
+
.map do |version_number, object_module|
|
101
|
+
begin
|
102
|
+
[version_number, object_module.const_get(type, false).const_get(method_name, false)]
|
103
|
+
rescue NameError
|
104
|
+
nil
|
105
|
+
end
|
93
106
|
end
|
94
|
-
|
95
|
-
.compact
|
107
|
+
.compact
|
96
108
|
|
97
|
-
|
98
|
-
|
99
|
-
|
109
|
+
if method_modules.empty?
|
110
|
+
raise ArgumentError, %Q("#{method}" is not a valid method on #{full_name} or has no updates)
|
111
|
+
end
|
100
112
|
|
101
|
-
|
102
|
-
|
103
|
-
|
113
|
+
mod.module_eval do
|
114
|
+
method_modules.each do |version_number, method_module|
|
115
|
+
include method_module if version_number > current_ruby_version
|
116
|
+
end
|
104
117
|
end
|
105
118
|
end
|
106
119
|
end
|
107
120
|
end
|
108
121
|
end
|
109
122
|
|
110
|
-
mod
|
123
|
+
Polyfill::Parcel.const_set("O#{mod.object_id}", mod)
|
111
124
|
end
|
data/lib/polyfill/v2_3.rb
CHANGED
@@ -1,9 +1,17 @@
|
|
1
|
+
require_relative 'v2_3/array'
|
2
|
+
require_relative 'v2_3/hash'
|
1
3
|
require_relative 'v2_3/enumerable'
|
4
|
+
require_relative 'v2_3/enumerator/lazy'
|
2
5
|
require_relative 'v2_3/string'
|
6
|
+
require_relative 'v2_3/struct'
|
3
7
|
|
4
8
|
module Polyfill
|
5
9
|
module V2_3
|
10
|
+
include Array
|
11
|
+
include Hash
|
6
12
|
include Enumerable
|
13
|
+
include Enumerator::Lazy
|
7
14
|
include String
|
15
|
+
include Struct
|
8
16
|
end
|
9
17
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Polyfill
|
2
|
+
module V2_3
|
3
|
+
module Array
|
4
|
+
module Instance
|
5
|
+
module Dig
|
6
|
+
module Method
|
7
|
+
def dig(head, *rest)
|
8
|
+
[head, *rest].reduce(self) do |value, accessor|
|
9
|
+
next_value =
|
10
|
+
case value
|
11
|
+
when ::Array
|
12
|
+
value.at(accessor)
|
13
|
+
when ::Hash
|
14
|
+
value[accessor]
|
15
|
+
when ::Struct
|
16
|
+
value[accessor] if value.members.include?(accessor)
|
17
|
+
else
|
18
|
+
begin
|
19
|
+
break value.dig(*rest)
|
20
|
+
rescue NoMethodError
|
21
|
+
raise TypeError, "#{value.class} does not have a #dig method"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
break nil if next_value.nil?
|
26
|
+
next_value
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
refine ::Array do
|
32
|
+
include Method
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.included(base)
|
36
|
+
base.include Method
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,10 +1,14 @@
|
|
1
1
|
require_relative 'instance/chunk_while'
|
2
|
+
require_relative 'instance/grep_v'
|
3
|
+
require_relative 'instance/slice_before'
|
2
4
|
|
3
5
|
module Polyfill
|
4
6
|
module V2_3
|
5
7
|
module Enumerable
|
6
8
|
module Instance
|
7
9
|
include ChunkWhile
|
10
|
+
include GrepV
|
11
|
+
include SliceBefore
|
8
12
|
end
|
9
13
|
end
|
10
14
|
end
|
@@ -7,11 +7,11 @@ module Polyfill
|
|
7
7
|
module ChunkWhile
|
8
8
|
module Method
|
9
9
|
def chunk_while
|
10
|
-
block = Proc.new
|
10
|
+
block = ::Proc.new
|
11
11
|
|
12
12
|
return [self] if size == 1
|
13
13
|
|
14
|
-
Enumerator.new do |yielder|
|
14
|
+
::Enumerator.new do |yielder|
|
15
15
|
output = []
|
16
16
|
each_cons(2).with_index(1) do |(a, b), run|
|
17
17
|
if run == size - 1
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
|
3
|
+
module Polyfill
|
4
|
+
module V2_3
|
5
|
+
module Enumerable
|
6
|
+
module Instance
|
7
|
+
module GrepV
|
8
|
+
module Method
|
9
|
+
def grep_v(pattern)
|
10
|
+
output = to_a - grep(pattern)
|
11
|
+
output.map!(&::Proc.new) if block_given?
|
12
|
+
output
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
refine ::Array do
|
17
|
+
include Method
|
18
|
+
end
|
19
|
+
refine ::Dir do
|
20
|
+
include Method
|
21
|
+
end
|
22
|
+
refine ::Enumerator do
|
23
|
+
include Method
|
24
|
+
end
|
25
|
+
refine ::Hash do
|
26
|
+
include Method
|
27
|
+
end
|
28
|
+
refine ::IO do
|
29
|
+
include Method
|
30
|
+
end
|
31
|
+
refine ::Range do
|
32
|
+
include Method
|
33
|
+
end
|
34
|
+
refine ::StringIO do
|
35
|
+
include Method
|
36
|
+
end
|
37
|
+
refine ::Struct do
|
38
|
+
include Method
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.included(base)
|
42
|
+
base.include Method
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Polyfill
|
2
|
+
module V2_3
|
3
|
+
module Enumerable
|
4
|
+
module Instance
|
5
|
+
module SliceBefore
|
6
|
+
module Method
|
7
|
+
def slice_before(*args)
|
8
|
+
if !args.empty? && block_given?
|
9
|
+
raise ArgumentError, 'wrong number of arguments (given 1, expected 0)'
|
10
|
+
end
|
11
|
+
|
12
|
+
super
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
refine ::Array do
|
17
|
+
include Method
|
18
|
+
end
|
19
|
+
refine ::Dir do
|
20
|
+
include Method
|
21
|
+
end
|
22
|
+
refine ::Enumerator do
|
23
|
+
include Method
|
24
|
+
end
|
25
|
+
refine ::Hash do
|
26
|
+
include Method
|
27
|
+
end
|
28
|
+
refine ::IO do
|
29
|
+
include Method
|
30
|
+
end
|
31
|
+
refine ::Range do
|
32
|
+
include Method
|
33
|
+
end
|
34
|
+
refine ::StringIO do
|
35
|
+
include Method
|
36
|
+
end
|
37
|
+
refine ::Struct do
|
38
|
+
include Method
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.included(base)
|
42
|
+
base.include Method
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Polyfill
|
2
|
+
module V2_3
|
3
|
+
module Enumerator
|
4
|
+
module Lazy
|
5
|
+
module Instance
|
6
|
+
module GrepV
|
7
|
+
module Method
|
8
|
+
using V2_3::Enumerable::Instance::GrepV
|
9
|
+
|
10
|
+
def grep_v(pattern)
|
11
|
+
::Enumerator::Lazy.new(self) do |yielder, element|
|
12
|
+
next if pattern === element # rubocop:disable Style/CaseEquality
|
13
|
+
|
14
|
+
yielder << (block_given? ? yield(element) : element)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
refine ::Enumerator::Lazy do
|
20
|
+
include Method
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.included(base)
|
24
|
+
base.include Method
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative 'instance/dig'
|
2
|
+
require_relative 'instance/fetch_values'
|
3
|
+
require_relative 'instance/to_proc'
|
4
|
+
|
5
|
+
module Polyfill
|
6
|
+
module V2_3
|
7
|
+
module Hash
|
8
|
+
module Instance
|
9
|
+
include Dig
|
10
|
+
include FetchValues
|
11
|
+
include ToProc
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Polyfill
|
2
|
+
module V2_3
|
3
|
+
module Hash
|
4
|
+
module Instance
|
5
|
+
module Dig
|
6
|
+
refine ::Hash do
|
7
|
+
include Array::Instance::Dig::Method
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.included(base)
|
11
|
+
base.include Array::Instance::Dig::Method
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Polyfill
|
2
|
+
module V2_3
|
3
|
+
module Hash
|
4
|
+
module Instance
|
5
|
+
module FetchValues
|
6
|
+
module Method
|
7
|
+
def fetch_values(*keys)
|
8
|
+
keys.each_with_object([]) do |key, values|
|
9
|
+
value =
|
10
|
+
if block_given?
|
11
|
+
fetch(key, &::Proc.new)
|
12
|
+
else
|
13
|
+
fetch(key)
|
14
|
+
end
|
15
|
+
|
16
|
+
values << value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
refine ::Hash do
|
22
|
+
include Method
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.included(base)
|
26
|
+
base.include Method
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Polyfill
|
2
|
+
module V2_3
|
3
|
+
module Hash
|
4
|
+
module Instance
|
5
|
+
module ToProc
|
6
|
+
module Method
|
7
|
+
def to_proc
|
8
|
+
method(:[]).to_proc
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
refine ::Hash do
|
13
|
+
include Method
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.included(base)
|
17
|
+
base.include Method
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/polyfill/v2_3/string.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Polyfill
|
2
|
+
module V2_3
|
3
|
+
module String
|
4
|
+
module Instance
|
5
|
+
module MinusUnary
|
6
|
+
module Method
|
7
|
+
def -@
|
8
|
+
frozen? ? self : dup.freeze
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
refine ::String do
|
13
|
+
include Method
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.included(base)
|
17
|
+
base.include Method
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Polyfill
|
2
|
+
module V2_3
|
3
|
+
module String
|
4
|
+
module Instance
|
5
|
+
module PlusUnary
|
6
|
+
module Method
|
7
|
+
def +@
|
8
|
+
frozen? ? dup : self
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
refine ::String do
|
13
|
+
include Method
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.included(base)
|
17
|
+
base.include Method
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Polyfill
|
2
|
+
module V2_3
|
3
|
+
module Struct
|
4
|
+
module Instance
|
5
|
+
module Dig
|
6
|
+
refine ::Struct do
|
7
|
+
include Array::Instance::Dig::Method
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.included(base)
|
11
|
+
base.include Array::Instance::Dig::Method
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
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: 0.
|
4
|
+
version: 0.6.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: 2017-
|
11
|
+
date: 2017-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -88,12 +88,31 @@ files:
|
|
88
88
|
- lib/polyfill.rb
|
89
89
|
- lib/polyfill/utils.rb
|
90
90
|
- lib/polyfill/v2_3.rb
|
91
|
+
- lib/polyfill/v2_3/array.rb
|
92
|
+
- lib/polyfill/v2_3/array/instance.rb
|
93
|
+
- lib/polyfill/v2_3/array/instance/dig.rb
|
91
94
|
- lib/polyfill/v2_3/enumerable.rb
|
92
95
|
- lib/polyfill/v2_3/enumerable/instance.rb
|
93
96
|
- lib/polyfill/v2_3/enumerable/instance/chunk_while.rb
|
97
|
+
- lib/polyfill/v2_3/enumerable/instance/grep_v.rb
|
98
|
+
- lib/polyfill/v2_3/enumerable/instance/slice_before.rb
|
99
|
+
- lib/polyfill/v2_3/enumerator/lazy.rb
|
100
|
+
- lib/polyfill/v2_3/enumerator/lazy/instance.rb
|
101
|
+
- lib/polyfill/v2_3/enumerator/lazy/instance/grep_v.rb
|
102
|
+
- lib/polyfill/v2_3/hash.rb
|
103
|
+
- lib/polyfill/v2_3/hash/instance.rb
|
104
|
+
- lib/polyfill/v2_3/hash/instance/dig.rb
|
105
|
+
- lib/polyfill/v2_3/hash/instance/fetch_values.rb
|
106
|
+
- lib/polyfill/v2_3/hash/instance/to_proc.rb
|
94
107
|
- lib/polyfill/v2_3/string.rb
|
95
108
|
- lib/polyfill/v2_3/string/class.rb
|
96
109
|
- lib/polyfill/v2_3/string/class/new.rb
|
110
|
+
- lib/polyfill/v2_3/string/instance.rb
|
111
|
+
- lib/polyfill/v2_3/string/instance/minus_unary.rb
|
112
|
+
- lib/polyfill/v2_3/string/instance/plus_unary.rb
|
113
|
+
- lib/polyfill/v2_3/struct.rb
|
114
|
+
- lib/polyfill/v2_3/struct/instance.rb
|
115
|
+
- lib/polyfill/v2_3/struct/instance/dig.rb
|
97
116
|
- lib/polyfill/v2_4.rb
|
98
117
|
- lib/polyfill/v2_4/array.rb
|
99
118
|
- lib/polyfill/v2_4/array/instance.rb
|