polyfill 0.3.0 → 0.4.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 +35 -0
- data/CHANGELOG.md +31 -2
- data/CONTRIBUTING.md +48 -17
- data/README.md +110 -80
- data/Rakefile +3 -1
- data/bin/console +3 -3
- data/lib/polyfill.rb +30 -19
- data/lib/polyfill/v2_4.rb +29 -12
- data/lib/polyfill/v2_4/array.rb +1 -1
- data/lib/polyfill/v2_4/array/instance.rb +3 -1
- data/lib/polyfill/v2_4/array/instance/concat.rb +5 -7
- data/lib/polyfill/v2_4/array/instance/sum.rb +17 -0
- data/lib/polyfill/v2_4/comparable.rb +1 -1
- data/lib/polyfill/v2_4/comparable/instance.rb +1 -1
- data/lib/polyfill/v2_4/comparable/instance/clamp.rb +11 -13
- data/lib/polyfill/v2_4/dir.rb +1 -1
- data/lib/polyfill/v2_4/dir/class.rb +1 -1
- data/lib/polyfill/v2_4/dir/class/empty_q.rb +5 -7
- data/lib/polyfill/v2_4/enumerable.rb +9 -0
- data/lib/polyfill/v2_4/enumerable/instance.rb +15 -0
- data/lib/polyfill/v2_4/enumerable/instance/chunk.rb +46 -0
- data/lib/polyfill/v2_4/enumerable/instance/sum.rb +52 -0
- data/lib/polyfill/v2_4/enumerable/instance/uniq.rb +45 -0
- data/lib/polyfill/v2_4/enumerator/lazy.rb +11 -0
- data/lib/polyfill/v2_4/enumerator/lazy/instance.rb +15 -0
- data/lib/polyfill/v2_4/enumerator/lazy/instance/chunk_while.rb +25 -0
- data/lib/polyfill/v2_4/enumerator/lazy/instance/uniq.rb +33 -0
- data/lib/polyfill/v2_4/file.rb +1 -1
- data/lib/polyfill/v2_4/file/class.rb +1 -1
- data/lib/polyfill/v2_4/file/class/empty_q.rb +5 -7
- data/lib/polyfill/v2_4/float.rb +1 -1
- data/lib/polyfill/v2_4/float/instance.rb +3 -3
- data/lib/polyfill/v2_4/float/instance/ceil.rb +8 -10
- data/lib/polyfill/v2_4/float/instance/floor.rb +7 -9
- data/lib/polyfill/v2_4/float/instance/truncate.rb +8 -10
- data/lib/polyfill/v2_4/hash.rb +1 -1
- data/lib/polyfill/v2_4/hash/instance.rb +4 -4
- data/lib/polyfill/v2_4/hash/instance/compact.rb +5 -7
- data/lib/polyfill/v2_4/hash/instance/compact_e.rb +5 -7
- data/lib/polyfill/v2_4/hash/instance/transform_values.rb +6 -8
- data/lib/polyfill/v2_4/hash/instance/transform_values_e.rb +6 -8
- data/lib/polyfill/v2_4/i_p_addr.rb +9 -0
- data/lib/polyfill/v2_4/i_p_addr/instance.rb +13 -0
- data/lib/polyfill/v2_4/i_p_addr/instance/equalequal.rb +27 -0
- data/lib/polyfill/v2_4/i_p_addr/instance/lessthanequalgreaterthan.rb +27 -0
- data/lib/polyfill/v2_4/integer.rb +1 -1
- data/lib/polyfill/v2_4/integer/instance.rb +5 -5
- data/lib/polyfill/v2_4/integer/instance/ceil.rb +7 -9
- data/lib/polyfill/v2_4/integer/instance/digits.rb +5 -7
- data/lib/polyfill/v2_4/integer/instance/floor.rb +7 -9
- data/lib/polyfill/v2_4/integer/instance/round.rb +7 -9
- data/lib/polyfill/v2_4/integer/instance/truncate.rb +7 -9
- data/lib/polyfill/v2_4/io.rb +2 -2
- data/lib/polyfill/v2_4/io/class.rb +2 -2
- data/lib/polyfill/v2_4/io/class/foreach.rb +21 -33
- data/lib/polyfill/v2_4/io/class/readlines.rb +12 -13
- data/lib/polyfill/v2_4/io/instance.rb +6 -4
- data/lib/polyfill/v2_4/io/instance/each_line.rb +20 -33
- data/lib/polyfill/v2_4/io/instance/gets.rb +12 -13
- data/lib/polyfill/v2_4/io/instance/lines.rb +54 -0
- data/lib/polyfill/v2_4/io/instance/readline.rb +12 -13
- data/lib/polyfill/v2_4/io/instance/readlines.rb +12 -13
- data/lib/polyfill/v2_4/match_data.rb +1 -1
- data/lib/polyfill/v2_4/match_data/instance.rb +2 -2
- data/lib/polyfill/v2_4/match_data/instance/named_captures.rb +5 -7
- data/lib/polyfill/v2_4/match_data/instance/values_at.rb +5 -7
- data/lib/polyfill/v2_4/numeric.rb +1 -1
- data/lib/polyfill/v2_4/numeric/instance.rb +6 -2
- data/lib/polyfill/v2_4/numeric/instance/clone.rb +23 -0
- data/lib/polyfill/v2_4/numeric/instance/dup.rb +23 -0
- data/lib/polyfill/v2_4/numeric/instance/finite_q.rb +5 -7
- data/lib/polyfill/v2_4/numeric/instance/infinite_q.rb +5 -7
- data/lib/polyfill/v2_4/object.rb +9 -0
- data/lib/polyfill/v2_4/object/instance.rb +11 -0
- data/lib/polyfill/v2_4/object/instance/clone.rb +29 -0
- data/lib/polyfill/v2_4/pathname.rb +9 -0
- data/lib/polyfill/v2_4/pathname/instance.rb +11 -0
- data/lib/polyfill/v2_4/pathname/instance/empty_q.rb +29 -0
- data/lib/polyfill/v2_4/regexp.rb +9 -0
- data/lib/polyfill/v2_4/regexp/instance.rb +11 -0
- data/lib/polyfill/v2_4/regexp/instance/match_q.rb +23 -0
- data/lib/polyfill/v2_4/string.rb +3 -1
- data/lib/polyfill/v2_4/string/class.rb +11 -0
- data/lib/polyfill/v2_4/string/class/new.rb +26 -0
- data/lib/polyfill/v2_4/string/instance.rb +12 -2
- data/lib/polyfill/v2_4/string/instance/casecmp_q.rb +23 -0
- data/lib/polyfill/v2_4/string/instance/concat.rb +5 -7
- data/lib/polyfill/v2_4/string/instance/each_line.rb +17 -0
- data/lib/polyfill/v2_4/string/instance/lines.rb +55 -0
- data/lib/polyfill/v2_4/string/instance/match_q.rb +23 -0
- data/lib/polyfill/v2_4/string/instance/prepend.rb +5 -7
- data/lib/polyfill/v2_4/string/instance/unpack1.rb +23 -0
- data/lib/polyfill/v2_4/string_io.rb +1 -1
- data/lib/polyfill/v2_4/string_io/instance.rb +4 -4
- data/lib/polyfill/v2_4/string_io/instance/each_line.rb +5 -7
- data/lib/polyfill/v2_4/string_io/instance/gets.rb +5 -7
- data/lib/polyfill/v2_4/string_io/instance/readline.rb +5 -7
- data/lib/polyfill/v2_4/string_io/instance/readlines.rb +5 -7
- data/lib/polyfill/v2_4/symbol.rb +9 -0
- data/lib/polyfill/v2_4/symbol/instance.rb +15 -0
- data/lib/polyfill/v2_4/symbol/instance/casecmp_q.rb +25 -0
- data/lib/polyfill/v2_4/symbol/instance/match.rb +27 -0
- data/lib/polyfill/v2_4/symbol/instance/match_q.rb +17 -0
- data/lib/polyfill/version.rb +1 -1
- data/polyfill.gemspec +1 -0
- metadata +56 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a78a97eb49d10c541939893c1df67dc431f56570
|
4
|
+
data.tar.gz: b56aa89aaafa5cf0ae1238c7a5d6a7b1be9277d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca64b371d0e8287f87f67be903b9b48be65f318ad6ae991d4789114addc5500d785638efc65d3bfd464b5769cc80a07be033cdef17770752a1da55c1a984d2b8
|
7
|
+
data.tar.gz: bdfce84cb85bb20c013584b259c0612468a103985007824a38b2f635fa4adc86a0f4182ea5aaa362d873eaef0f789a02cb38a4f47df3810d6f792b75ddedf081
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.3
|
3
|
+
Metrics/AbcSize:
|
4
|
+
Enabled: false
|
5
|
+
Metrics/BlockLength:
|
6
|
+
Enabled: false
|
7
|
+
Metrics/CyclomaticComplexity:
|
8
|
+
Enabled: false
|
9
|
+
Metrics/LineLength:
|
10
|
+
Enabled: false
|
11
|
+
Metrics/MethodLength:
|
12
|
+
Enabled: false
|
13
|
+
Metrics/PerceivedComplexity:
|
14
|
+
Enabled: false
|
15
|
+
Style/AsciiComments:
|
16
|
+
Enabled: false
|
17
|
+
Style/BarePercentLiterals:
|
18
|
+
EnforcedStyle: percent_q
|
19
|
+
Style/ClassAndModuleCamelCase:
|
20
|
+
Enabled: false
|
21
|
+
Style/Documentation:
|
22
|
+
Enabled: false
|
23
|
+
Style/DoubleNegation:
|
24
|
+
Enabled: false
|
25
|
+
Style/FrozenStringLiteralComment:
|
26
|
+
Enabled: false
|
27
|
+
Style/MultilineMethodCallIndentation:
|
28
|
+
EnforcedStyle: indented
|
29
|
+
Style/NumericPredicate:
|
30
|
+
EnforcedStyle: comparison
|
31
|
+
Style/PercentLiteralDelimiters:
|
32
|
+
PreferredDelimiters:
|
33
|
+
'%W': '[]'
|
34
|
+
'%i': '[]'
|
35
|
+
'%w': '[]'
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,32 @@
|
|
1
|
-
# [0.
|
1
|
+
# [0.4.0][] (2017-03-24)
|
2
|
+
|
3
|
+
## Added
|
4
|
+
|
5
|
+
- v2.4 Array#sum
|
6
|
+
- v2.4 Enumerable#chunk
|
7
|
+
- v2.4 Enumerable#sum
|
8
|
+
- v2.4 Enumerable#uniq
|
9
|
+
- v2.4 Enumerator::Lazy#chunk_while
|
10
|
+
- v2.4 Enumerator::Lazy#uniq
|
11
|
+
- v2.4 IO#lines
|
12
|
+
- v2.4 IPAddr#==
|
13
|
+
- v2.4 IPAddr#<=>
|
14
|
+
- v2.4 Numeric#clone
|
15
|
+
- v2.4 Numeric#dup
|
16
|
+
- v2.4 Object#clone
|
17
|
+
- v2.4 Pathname#empty?
|
18
|
+
- v2.4 Regexp#match?
|
19
|
+
- v2.4 String#casecmp?
|
20
|
+
- v2.4 String#each_line
|
21
|
+
- v2.4 String#lines
|
22
|
+
- v2.4 String#match?
|
23
|
+
- v2.4 String.new
|
24
|
+
- v2.4 String#unpack1
|
25
|
+
- v2.4 Symbol#casecmp?
|
26
|
+
- v2.4 Symbol#match
|
27
|
+
- v2.4 Symbol#match?
|
28
|
+
|
29
|
+
# [0.3.0][] (2017-03-19)
|
2
30
|
|
3
31
|
## Added
|
4
32
|
|
@@ -19,7 +47,7 @@
|
|
19
47
|
|
20
48
|
- New way to select methods that doesn't rely on knowing the module structure
|
21
49
|
|
22
|
-
# [0.2.0][] (2017-03-
|
50
|
+
# [0.2.0][] (2017-03-17)
|
23
51
|
|
24
52
|
## Added
|
25
53
|
|
@@ -54,6 +82,7 @@
|
|
54
82
|
- v2.4 String#concat?
|
55
83
|
- v2.4 String#prepend?
|
56
84
|
|
85
|
+
[0.4.0]: https://github.com/AaronLasseigne/polyfill/compare/v0.3.0...v0.4.0
|
57
86
|
[0.3.0]: https://github.com/AaronLasseigne/polyfill/compare/v0.2.0...v0.3.0
|
58
87
|
[0.2.0]: https://github.com/AaronLasseigne/polyfill/compare/v0.1.0...v0.2.0
|
59
88
|
[0.1.0]: https://github.com/AaronLasseigne/polyfill/compare/v0.0.0...v0.1.0
|
data/CONTRIBUTING.md
CHANGED
@@ -1,33 +1,54 @@
|
|
1
1
|
## Contributing
|
2
2
|
|
3
|
+
There are many ways to contribute. You can [file a bug], improve the
|
4
|
+
[documentation], or submit [new code](#code). Finding all the changes
|
5
|
+
for any given Ruby version can be difficult. If something is missing
|
6
|
+
please add it to the documentation.
|
7
|
+
|
8
|
+
### Code
|
9
|
+
|
10
|
+
These are the steps that you'll need to follow for submitting code:
|
11
|
+
|
3
12
|
1. [Fork](#fork)
|
4
13
|
2. [Tests](#tests)
|
5
|
-
3. [
|
14
|
+
3. [Lib](#lib)
|
6
15
|
4. [Push and Submit](#push-and-submit)
|
7
16
|
5. [Refine Until Merged](#refine-until-merged)
|
8
17
|
|
9
|
-
|
18
|
+
#### Fork
|
10
19
|
|
11
|
-
[Fork]
|
20
|
+
[Fork] the repo.
|
12
21
|
|
13
|
-
|
22
|
+
#### Tests
|
14
23
|
|
15
|
-
The goal is to produce code that is identical to the real method.
|
16
|
-
|
17
|
-
[Ruby Spec Suite]
|
18
|
-
|
19
|
-
|
20
|
-
own tests. If the feature is new then you'll need to test every aspect
|
21
|
-
of it.
|
24
|
+
The goal is to produce code that is identical to the real method. To
|
25
|
+
ensure that nothing breaks and the new code is good we need tests! One
|
26
|
+
of the best places to find examples is the [Ruby Spec Suite]. If the
|
27
|
+
have tests for the new functionality then make sure those same cases
|
28
|
+
are covered.
|
22
29
|
|
23
30
|
If this is a change that adds to an existing feature make sure to have
|
24
31
|
a basic test of the old functionality and then test all of the new
|
25
|
-
functionality.
|
32
|
+
functionality. These tests are typically grouped into two contexts.
|
26
33
|
|
27
|
-
|
28
|
-
|
34
|
+
```ruby
|
35
|
+
RSpec.describe 'Obj#method' do
|
36
|
+
context 'existing behavior' do
|
37
|
+
# smoke test or two here
|
38
|
+
end
|
39
|
+
|
40
|
+
context '2.4' do
|
41
|
+
# changes added in 2.4
|
42
|
+
end
|
43
|
+
end
|
44
|
+
```
|
29
45
|
|
30
|
-
|
46
|
+
Also make sure that your code passes rubocop. You can run
|
47
|
+
`bundle exec rake` to execute the tests and run rubocop. If there's
|
48
|
+
a good reason to violate rubocop (e.g. an optimization) then please
|
49
|
+
bring it up and we'll figure it out.
|
50
|
+
|
51
|
+
#### Lib
|
31
52
|
|
32
53
|
The directory structure follows the module structure. Files are added
|
33
54
|
(`require` and `include`) one directly level up from their location.
|
@@ -38,6 +59,11 @@ The structure is formulaic so looking through an existing example
|
|
38
59
|
or two should clarify what to do. If you're not sure how to proceed,
|
39
60
|
please reach out and we'll figure it out.
|
40
61
|
|
62
|
+
Reusing the names of core classes means that in your methods you'll
|
63
|
+
need to make sure you reference the top level class by preceding it
|
64
|
+
with `::` (e.g. `::File`). This can be a frustrating mistake so be
|
65
|
+
mindful.
|
66
|
+
|
41
67
|
Partial implementations of features are welcome as long as they
|
42
68
|
bring value. Generally it's only ok to leave out part of the feature
|
43
69
|
when that part is very hard and/or secondary to the primary
|
@@ -46,14 +72,19 @@ accepted may seem a bit arbitrary. If you're unsure, please reach out
|
|
46
72
|
and we'll discuss. I'd hate to see a bunch of work done only to get
|
47
73
|
rejected.
|
48
74
|
|
49
|
-
|
75
|
+
#### Push and Submit
|
50
76
|
|
51
77
|
Push your branch up to your fork. Submit a pull request via
|
52
78
|
GitHub.
|
53
79
|
|
54
|
-
|
80
|
+
#### Refine Until Merged
|
55
81
|
|
56
82
|
There are weird edge cases and particulars that might need to be
|
57
83
|
changed. Don't worry if you get a lot of comments on your pull
|
58
84
|
request. That's why we have code reviews. People miss things and more
|
59
85
|
eyes catch more issues. After everything is fixed: VICTORY!
|
86
|
+
|
87
|
+
[file a bug]: https://github.com/AaronLasseigne/polyfill/issues/new
|
88
|
+
[documentation]: README.md
|
89
|
+
[Fork]: https://github.com/AaronLasseigne/polyfill/fork
|
90
|
+
[Ruby Spec Suite]: https://github.com/ruby/spec
|
data/README.md
CHANGED
@@ -32,7 +32,7 @@ See the [implementation table](#implementation-table) for specifics about what h
|
|
32
32
|
Add it to your Gemfile:
|
33
33
|
|
34
34
|
```ruby
|
35
|
-
gem 'polyfill', '0.
|
35
|
+
gem 'polyfill', '0.4.0'
|
36
36
|
```
|
37
37
|
|
38
38
|
Or install it manually:
|
@@ -69,6 +69,12 @@ using Polyfill(
|
|
69
69
|
)
|
70
70
|
```
|
71
71
|
|
72
|
+
If you want all of the methods for a particular class you can use `:all`.
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
using Polyfill(Numeric: :all)
|
76
|
+
```
|
77
|
+
|
72
78
|
Methods can be included in the same way. Prior to Ruby 2.4, refinements did
|
73
79
|
not work on modules. In order to get methods you'll need to include them after
|
74
80
|
the module. Calling `using` on a module will add it to all core Ruby classes
|
@@ -86,84 +92,108 @@ end
|
|
86
92
|
|
87
93
|
### 2.3 to 2.4
|
88
94
|
|
89
|
-
| Object | Method
|
90
|
-
| ---------------- |
|
91
|
-
| Array | #concat
|
92
|
-
| | #max
|
93
|
-
| | #min
|
94
|
-
| | #pack
|
95
|
-
| | #sum
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
| | #uniq
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
| | #
|
110
|
-
| | #
|
111
|
-
|
|
112
|
-
|
|
113
|
-
| | #
|
114
|
-
| | #
|
115
|
-
|
|
116
|
-
| | #
|
117
|
-
|
|
118
|
-
| |
|
119
|
-
| | #
|
120
|
-
|
|
121
|
-
| |
|
122
|
-
| |
|
123
|
-
|
|
124
|
-
|
|
125
|
-
| | #
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
| |
|
134
|
-
|
|
135
|
-
|
|
136
|
-
| | #
|
137
|
-
|
|
138
|
-
| | #
|
139
|
-
| | #
|
140
|
-
| | #
|
141
|
-
|
|
142
|
-
|
|
143
|
-
| | #
|
144
|
-
| | #
|
145
|
-
| | #
|
146
|
-
| | #
|
147
|
-
| | #
|
148
|
-
|
|
149
|
-
|
|
150
|
-
| | #
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
| | #
|
156
|
-
|
|
157
|
-
| | #
|
158
|
-
| | #
|
159
|
-
| | #
|
160
|
-
| | #
|
161
|
-
| | #
|
162
|
-
| | #
|
163
|
-
|
|
164
|
-
| |
|
165
|
-
|
|
166
|
-
|
|
95
|
+
| Object | Method | Implemented | Notes |
|
96
|
+
| ---------------- | ------------------------ | ----------- | ----- |
|
97
|
+
| Array | #concat | Yes |
|
98
|
+
| | #max | No | This method already existed but was inherited from `Enumerable`. It was optimized on `Array` so redefining `Enumerable#max` no longer affects this.
|
99
|
+
| | #min | No | This method already existed but was inherited from `Enumerable`. It was optimized on `Array` so redefining `Enumerable#min` no longer affects this.
|
100
|
+
| | #pack | No |
|
101
|
+
| | #sum | Yes |
|
102
|
+
| Binding | #irb | No |
|
103
|
+
| Comparable | #clamp | Yes |
|
104
|
+
| CSV | #new | No |
|
105
|
+
| Dir | .empty? | Yes |
|
106
|
+
| Enumerable | #chunk | Yes |
|
107
|
+
| | #sum | Yes |
|
108
|
+
| | #uniq | Yes |
|
109
|
+
| Enumerator::Lazy | #chunk_while | Yes |
|
110
|
+
| | #uniq | Yes |
|
111
|
+
| File | .empty? | Yes |
|
112
|
+
| FileTest | .empty? | No |
|
113
|
+
| Float | #ceil | Yes |
|
114
|
+
| | #floor | Yes |
|
115
|
+
| | #round | No |
|
116
|
+
| | #truncate | Yes |
|
117
|
+
| Hash | #compact | Yes |
|
118
|
+
| | #compact! | Yes |
|
119
|
+
| | #transform_values | Yes |
|
120
|
+
| | #transform_values! | Yes |
|
121
|
+
| Integer | #ceil | Yes |
|
122
|
+
| | #digits | Yes |
|
123
|
+
| | #floor | Yes |
|
124
|
+
| | #round | Yes |
|
125
|
+
| | #truncate | Yes |
|
126
|
+
| IO | #each_line | Yes |
|
127
|
+
| | .foreach | Yes |
|
128
|
+
| | #gets | Yes |
|
129
|
+
| | #lines | Yes |
|
130
|
+
| | #readline | Yes |
|
131
|
+
| | #readlines | Yes |
|
132
|
+
| | .readlines | Yes |
|
133
|
+
| IPAddr | #== | Yes |
|
134
|
+
| | #<=> | Yes |
|
135
|
+
| Logger | #new | No |
|
136
|
+
| MatchData | #named_captures | Yes |
|
137
|
+
| | #values_at | Yes |
|
138
|
+
| Module | #refine | No |
|
139
|
+
| | .used_modules | No |
|
140
|
+
| Net::HTTP | #post | No |
|
141
|
+
| Net::FTP | #new | No |
|
142
|
+
| | #status | No |
|
143
|
+
| Numeric | #clone | Yes |
|
144
|
+
| | #dup | Yes |
|
145
|
+
| | #finite? | Yes |
|
146
|
+
| | #infinite? | Yes |
|
147
|
+
| Object | #clone | Yes |
|
148
|
+
| OptionParser | #order | No |
|
149
|
+
| | #order! | No |
|
150
|
+
| | #parse | No |
|
151
|
+
| | #parse! | No |
|
152
|
+
| | #permute | No |
|
153
|
+
| | #permute! | No |
|
154
|
+
| Pathname | #empty? | Yes |
|
155
|
+
| Readline | #quoting_detection_proc | No |
|
156
|
+
| | #quoting_detection_proc= | No |
|
157
|
+
| REXML::Element | #[] | No |
|
158
|
+
| Rational | #round | No |
|
159
|
+
| Regexp | #match? | Yes |
|
160
|
+
| Set | #compare_by_identity | No |
|
161
|
+
| | #compare_by_identity? | No |
|
162
|
+
| String | #capitalize | No |
|
163
|
+
| | #capitalize! | No |
|
164
|
+
| | #casecmp? | Partial | Does not support Unicode characters.
|
165
|
+
| | #concat | Yes |
|
166
|
+
| | #downcase | No |
|
167
|
+
| | #downcase! | No |
|
168
|
+
| | #each_line | Yes |
|
169
|
+
| | #lines | Yes |
|
170
|
+
| | #match? | Yes |
|
171
|
+
| | .new | Partial | Allows `:capacity` option to pass but does nothing.
|
172
|
+
| | #prepend | Yes |
|
173
|
+
| | #swapcase | No |
|
174
|
+
| | #swapcase! | No |
|
175
|
+
| | #unpack1 | Yes |
|
176
|
+
| | #upcase | No |
|
177
|
+
| | #upcase! | No |
|
178
|
+
| StringIO | #each_line | Yes |
|
179
|
+
| | #gets | Yes |
|
180
|
+
| | #readline | Yes |
|
181
|
+
| | #readlines | Yes |
|
182
|
+
| Symbol | #capitalize | No |
|
183
|
+
| | #capitalize! | No |
|
184
|
+
| | #casecmp? | Partial | Does not support Unicode characters.
|
185
|
+
| | #downcase | No |
|
186
|
+
| | #downcase! | No |
|
187
|
+
| | #match | Yes |
|
188
|
+
| | #match? | Yes |
|
189
|
+
| | #swapcase | No |
|
190
|
+
| | #swapcase! | No |
|
191
|
+
| | #upcase | No |
|
192
|
+
| | #upcase! | No |
|
193
|
+
| Thread | #report\_on\_exception | No |
|
194
|
+
| | .report\_on\_exception | No |
|
195
|
+
| TracePoint | #callee_id | No |
|
196
|
+
| Warning | #warn | No |
|
167
197
|
|
168
198
|
## Contributing
|
169
199
|
|
@@ -172,4 +202,4 @@ Please read the [contributing file](CONTRIBUTING.md) prior to pull requests.
|
|
172
202
|
|
173
203
|
## Credits
|
174
204
|
|
175
|
-
Polyfill is licensed under the [MIT License](LICENSE.
|
205
|
+
Polyfill is licensed under the [MIT License](LICENSE.txt).
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'polyfill'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "polyfill"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start(__FILE__)
|
data/lib/polyfill.rb
CHANGED
@@ -5,7 +5,7 @@ module Polyfill
|
|
5
5
|
include V2_4
|
6
6
|
end
|
7
7
|
|
8
|
-
def Polyfill(options)
|
8
|
+
def Polyfill(options) # rubocop:disable Style/MethodName
|
9
9
|
mod = Module.new
|
10
10
|
|
11
11
|
klasses, others = options.partition { |key,| key[/\A[A-Z]/] }
|
@@ -14,15 +14,23 @@ def Polyfill(options)
|
|
14
14
|
raise ArgumentError, "unknown keyword: #{others.first[0]}"
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
needs_update = RUBY_VERSION[/\A(\d+\.\d+)/, 1] < '2.4'
|
18
|
+
|
19
|
+
klasses.each do |names, methods|
|
20
|
+
class_or_module_mod = names
|
21
|
+
.to_s
|
22
|
+
.split('::')
|
23
|
+
.reduce(Polyfill::V2_4) do |current_mod, name|
|
24
|
+
begin
|
25
|
+
current_mod.const_get(name, false)
|
26
|
+
rescue NameError
|
27
|
+
raise ArgumentError, %Q("#{names}" is not a valid class or has no updates)
|
28
|
+
end
|
23
29
|
end
|
24
30
|
|
25
31
|
if methods == :all
|
32
|
+
next unless needs_update
|
33
|
+
|
26
34
|
mod.module_eval do
|
27
35
|
include class_or_module_mod
|
28
36
|
end
|
@@ -37,17 +45,18 @@ def Polyfill(options)
|
|
37
45
|
else
|
38
46
|
raise ArgumentError, %Q("#{method}" must start with a "." if it's a class method or "#" if it's an instance method)
|
39
47
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
48
|
+
|
49
|
+
method_name = method[1..-1]
|
50
|
+
symbol_conversions = {
|
51
|
+
'=' => 'equal',
|
52
|
+
'<' => 'lessthan',
|
53
|
+
'>' => 'greaterthan',
|
54
|
+
'?' => '_q',
|
55
|
+
'!' => '_e'
|
56
|
+
}
|
57
|
+
method_name.gsub!(/[#{symbol_conversions.keys.join}]/o, symbol_conversions)
|
49
58
|
method_name.capitalize!
|
50
|
-
method_name.gsub!(/_(.)/) {
|
59
|
+
method_name.gsub!(/_(.)/) { |match| match[1].capitalize }
|
51
60
|
|
52
61
|
method_mod =
|
53
62
|
begin
|
@@ -55,11 +64,13 @@ def Polyfill(options)
|
|
55
64
|
.const_get(type, false)
|
56
65
|
.const_get(method_name, false)
|
57
66
|
rescue NameError
|
58
|
-
raise ArgumentError, %Q("#{method}" is not a valid method on #{
|
67
|
+
raise ArgumentError, %Q("#{method}" is not a valid method on #{names} or has no updates)
|
59
68
|
end
|
60
69
|
|
70
|
+
next unless needs_update
|
71
|
+
|
61
72
|
mod.module_eval do
|
62
|
-
include
|
73
|
+
include method_mod
|
63
74
|
end
|
64
75
|
end
|
65
76
|
end
|