polyfill 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +35 -0
  3. data/CHANGELOG.md +31 -2
  4. data/CONTRIBUTING.md +48 -17
  5. data/README.md +110 -80
  6. data/Rakefile +3 -1
  7. data/bin/console +3 -3
  8. data/lib/polyfill.rb +30 -19
  9. data/lib/polyfill/v2_4.rb +29 -12
  10. data/lib/polyfill/v2_4/array.rb +1 -1
  11. data/lib/polyfill/v2_4/array/instance.rb +3 -1
  12. data/lib/polyfill/v2_4/array/instance/concat.rb +5 -7
  13. data/lib/polyfill/v2_4/array/instance/sum.rb +17 -0
  14. data/lib/polyfill/v2_4/comparable.rb +1 -1
  15. data/lib/polyfill/v2_4/comparable/instance.rb +1 -1
  16. data/lib/polyfill/v2_4/comparable/instance/clamp.rb +11 -13
  17. data/lib/polyfill/v2_4/dir.rb +1 -1
  18. data/lib/polyfill/v2_4/dir/class.rb +1 -1
  19. data/lib/polyfill/v2_4/dir/class/empty_q.rb +5 -7
  20. data/lib/polyfill/v2_4/enumerable.rb +9 -0
  21. data/lib/polyfill/v2_4/enumerable/instance.rb +15 -0
  22. data/lib/polyfill/v2_4/enumerable/instance/chunk.rb +46 -0
  23. data/lib/polyfill/v2_4/enumerable/instance/sum.rb +52 -0
  24. data/lib/polyfill/v2_4/enumerable/instance/uniq.rb +45 -0
  25. data/lib/polyfill/v2_4/enumerator/lazy.rb +11 -0
  26. data/lib/polyfill/v2_4/enumerator/lazy/instance.rb +15 -0
  27. data/lib/polyfill/v2_4/enumerator/lazy/instance/chunk_while.rb +25 -0
  28. data/lib/polyfill/v2_4/enumerator/lazy/instance/uniq.rb +33 -0
  29. data/lib/polyfill/v2_4/file.rb +1 -1
  30. data/lib/polyfill/v2_4/file/class.rb +1 -1
  31. data/lib/polyfill/v2_4/file/class/empty_q.rb +5 -7
  32. data/lib/polyfill/v2_4/float.rb +1 -1
  33. data/lib/polyfill/v2_4/float/instance.rb +3 -3
  34. data/lib/polyfill/v2_4/float/instance/ceil.rb +8 -10
  35. data/lib/polyfill/v2_4/float/instance/floor.rb +7 -9
  36. data/lib/polyfill/v2_4/float/instance/truncate.rb +8 -10
  37. data/lib/polyfill/v2_4/hash.rb +1 -1
  38. data/lib/polyfill/v2_4/hash/instance.rb +4 -4
  39. data/lib/polyfill/v2_4/hash/instance/compact.rb +5 -7
  40. data/lib/polyfill/v2_4/hash/instance/compact_e.rb +5 -7
  41. data/lib/polyfill/v2_4/hash/instance/transform_values.rb +6 -8
  42. data/lib/polyfill/v2_4/hash/instance/transform_values_e.rb +6 -8
  43. data/lib/polyfill/v2_4/i_p_addr.rb +9 -0
  44. data/lib/polyfill/v2_4/i_p_addr/instance.rb +13 -0
  45. data/lib/polyfill/v2_4/i_p_addr/instance/equalequal.rb +27 -0
  46. data/lib/polyfill/v2_4/i_p_addr/instance/lessthanequalgreaterthan.rb +27 -0
  47. data/lib/polyfill/v2_4/integer.rb +1 -1
  48. data/lib/polyfill/v2_4/integer/instance.rb +5 -5
  49. data/lib/polyfill/v2_4/integer/instance/ceil.rb +7 -9
  50. data/lib/polyfill/v2_4/integer/instance/digits.rb +5 -7
  51. data/lib/polyfill/v2_4/integer/instance/floor.rb +7 -9
  52. data/lib/polyfill/v2_4/integer/instance/round.rb +7 -9
  53. data/lib/polyfill/v2_4/integer/instance/truncate.rb +7 -9
  54. data/lib/polyfill/v2_4/io.rb +2 -2
  55. data/lib/polyfill/v2_4/io/class.rb +2 -2
  56. data/lib/polyfill/v2_4/io/class/foreach.rb +21 -33
  57. data/lib/polyfill/v2_4/io/class/readlines.rb +12 -13
  58. data/lib/polyfill/v2_4/io/instance.rb +6 -4
  59. data/lib/polyfill/v2_4/io/instance/each_line.rb +20 -33
  60. data/lib/polyfill/v2_4/io/instance/gets.rb +12 -13
  61. data/lib/polyfill/v2_4/io/instance/lines.rb +54 -0
  62. data/lib/polyfill/v2_4/io/instance/readline.rb +12 -13
  63. data/lib/polyfill/v2_4/io/instance/readlines.rb +12 -13
  64. data/lib/polyfill/v2_4/match_data.rb +1 -1
  65. data/lib/polyfill/v2_4/match_data/instance.rb +2 -2
  66. data/lib/polyfill/v2_4/match_data/instance/named_captures.rb +5 -7
  67. data/lib/polyfill/v2_4/match_data/instance/values_at.rb +5 -7
  68. data/lib/polyfill/v2_4/numeric.rb +1 -1
  69. data/lib/polyfill/v2_4/numeric/instance.rb +6 -2
  70. data/lib/polyfill/v2_4/numeric/instance/clone.rb +23 -0
  71. data/lib/polyfill/v2_4/numeric/instance/dup.rb +23 -0
  72. data/lib/polyfill/v2_4/numeric/instance/finite_q.rb +5 -7
  73. data/lib/polyfill/v2_4/numeric/instance/infinite_q.rb +5 -7
  74. data/lib/polyfill/v2_4/object.rb +9 -0
  75. data/lib/polyfill/v2_4/object/instance.rb +11 -0
  76. data/lib/polyfill/v2_4/object/instance/clone.rb +29 -0
  77. data/lib/polyfill/v2_4/pathname.rb +9 -0
  78. data/lib/polyfill/v2_4/pathname/instance.rb +11 -0
  79. data/lib/polyfill/v2_4/pathname/instance/empty_q.rb +29 -0
  80. data/lib/polyfill/v2_4/regexp.rb +9 -0
  81. data/lib/polyfill/v2_4/regexp/instance.rb +11 -0
  82. data/lib/polyfill/v2_4/regexp/instance/match_q.rb +23 -0
  83. data/lib/polyfill/v2_4/string.rb +3 -1
  84. data/lib/polyfill/v2_4/string/class.rb +11 -0
  85. data/lib/polyfill/v2_4/string/class/new.rb +26 -0
  86. data/lib/polyfill/v2_4/string/instance.rb +12 -2
  87. data/lib/polyfill/v2_4/string/instance/casecmp_q.rb +23 -0
  88. data/lib/polyfill/v2_4/string/instance/concat.rb +5 -7
  89. data/lib/polyfill/v2_4/string/instance/each_line.rb +17 -0
  90. data/lib/polyfill/v2_4/string/instance/lines.rb +55 -0
  91. data/lib/polyfill/v2_4/string/instance/match_q.rb +23 -0
  92. data/lib/polyfill/v2_4/string/instance/prepend.rb +5 -7
  93. data/lib/polyfill/v2_4/string/instance/unpack1.rb +23 -0
  94. data/lib/polyfill/v2_4/string_io.rb +1 -1
  95. data/lib/polyfill/v2_4/string_io/instance.rb +4 -4
  96. data/lib/polyfill/v2_4/string_io/instance/each_line.rb +5 -7
  97. data/lib/polyfill/v2_4/string_io/instance/gets.rb +5 -7
  98. data/lib/polyfill/v2_4/string_io/instance/readline.rb +5 -7
  99. data/lib/polyfill/v2_4/string_io/instance/readlines.rb +5 -7
  100. data/lib/polyfill/v2_4/symbol.rb +9 -0
  101. data/lib/polyfill/v2_4/symbol/instance.rb +15 -0
  102. data/lib/polyfill/v2_4/symbol/instance/casecmp_q.rb +25 -0
  103. data/lib/polyfill/v2_4/symbol/instance/match.rb +27 -0
  104. data/lib/polyfill/v2_4/symbol/instance/match_q.rb +17 -0
  105. data/lib/polyfill/version.rb +1 -1
  106. data/polyfill.gemspec +1 -0
  107. metadata +56 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c8ffdd9cc5cb6a688ba0bcedc79a627c63f1916f
4
- data.tar.gz: 3028c8eed9c64fd43d65d049c4aadeb7843aac48
3
+ metadata.gz: a78a97eb49d10c541939893c1df67dc431f56570
4
+ data.tar.gz: b56aa89aaafa5cf0ae1238c7a5d6a7b1be9277d8
5
5
  SHA512:
6
- metadata.gz: 8fc2cf9a4bc8f49268c396d7a7caf911941f8a4c9b05ecf4c84f93bb60e99c2fb6e1becf7d824fa34a89534f653a66586f6bfd826b788bd0cf387c5f24711bec
7
- data.tar.gz: '082b8f86fe28e66a3aedd6bcd809c09720ed37bf5745fbc7d1b9f1a23de7ac9fd5cb6808ff5f6da4dcea57b909866da0dbefc4c06c2ecf2376fa4d090187280d'
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.3.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-16)
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. [Code](#code)
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
- ### Fork
18
+ #### Fork
10
19
 
11
- [Fork](https://github.com/AaronLasseigne/polyfill/fork) the repo.
20
+ [Fork] the repo.
12
21
 
13
- ### Tests
22
+ #### Tests
14
23
 
15
- The goal is to produce code that is identical to the real method. One
16
- of the best places to find examples is the
17
- [Ruby Spec Suite](https://github.com/ruby/spec). If tests exist there,
18
- please copy them out and change them from MSpec to RSpec. Newer
19
- methods may not be available in which case you'll have to add your
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
- Looking over an existing test or two should give you an idea of what
28
- to do.
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
- ### Code
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
- ### Push and Submit
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
- ### Refine Until Merged
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.3.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 | Implemented | Notes |
90
- | ---------------- | ---------------------- | ----------- | ----- |
91
- | Array | #concat | Yes |
92
- | | #max | No |
93
- | | #min | No |
94
- | | #pack | No |
95
- | | #sum | No |
96
- | Comparable | #clamp | Yes |
97
- | Dir | .empty? | Yes |
98
- | Enumerable | #chunk | No |
99
- | | #sum | No |
100
- | | #uniq | No |
101
- | Enumerator::Lazy | #chunk_while | No |
102
- | | #uniq | No |
103
- | File | .empty? | Yes |
104
- | Float | #ceil | Yes |
105
- | | #floor | Yes |
106
- | | #round | No |
107
- | | #truncate | Yes |
108
- | Hash | #compact | Yes |
109
- | | #compact! | Yes |
110
- | | #transform_values | Yes |
111
- | | #transform_values! | Yes |
112
- | Integer | #ceil | Yes |
113
- | | #digits | Yes |
114
- | | #floor | Yes |
115
- | | #round | Yes |
116
- | | #truncate | Yes |
117
- | IO | #each_line | Yes |
118
- | | .foreach | Yes |
119
- | | #gets | Yes |
120
- | | #readline | Yes |
121
- | | #readlines | Yes |
122
- | | .readlines | Yes |
123
- | Kernel | #clone | No |
124
- | MatchData | #named_captures | Yes |
125
- | | #values_at | Yes |
126
- | Module | #refine | No |
127
- | | .used_modules | No |
128
- | Numeric | #finite? | Yes |
129
- | | #infinite? | Yes |
130
- | Rational | #round | No |
131
- | Regexp | #match? | No |
132
- | String | #capitalize | No |
133
- | | #capitalize! | No |
134
- | | #casecmp? | No |
135
- | | #concat | Yes |
136
- | | #downcase | No |
137
- | | #downcase! | No |
138
- | | #each_line | No |
139
- | | #lines | No |
140
- | | #match? | No |
141
- | | .new | No |
142
- | | #prepend | Yes |
143
- | | #swapcase | No |
144
- | | #swapcase! | No |
145
- | | #unpack1 | No |
146
- | | #upcase | No |
147
- | | #upcase! | No |
148
- | StringIO | #each_line | Yes |
149
- | | #gets | Yes |
150
- | | #readline | Yes |
151
- | | #readlines | Yes |
152
- | Symbol | #capitalize | No |
153
- | | #capitalize! | No |
154
- | | #casecmp? | No |
155
- | | #downcase | No |
156
- | | #downcase! | No |
157
- | | #match | No |
158
- | | #match? | No |
159
- | | #swapcase | No |
160
- | | #swapcase! | No |
161
- | | #upcase | No |
162
- | | #upcase! | No |
163
- | Thread | #report\_on\_exception | No |
164
- | | .report\_on\_exception | No |
165
- | TracePoint | #callee_id | No |
166
- | Warning | #warn | No |
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.md).
205
+ Polyfill is licensed under the [MIT License](LICENSE.txt).
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'bundler/gem_tasks'
2
2
  require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
3
4
 
4
5
  RSpec::Core::RakeTask.new(:spec)
6
+ RuboCop::RakeTask.new
5
7
 
6
- task default: :spec
8
+ task default: %i[spec rubocop]
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "polyfill"
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 "irb"
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
- klasses.each do |name, methods|
18
- class_or_module_mod =
19
- begin
20
- Polyfill::V2_4.const_get(name, false)
21
- rescue NameError
22
- raise ArgumentError, %Q("#{name}" is not a valid class or has no updates)
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
- method_name =
41
- case method[-1]
42
- when '?'
43
- "#{method[1..-2]}_q"
44
- when '!'
45
- "#{method[1..-2]}_e"
46
- else
47
- method[1..-1]
48
- end
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!(/_(.)/) { $1.capitalize }
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 #{name} or has no updates)
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 class_or_module_mod.const_get(type, false).const_get(method_name, false)
73
+ include method_mod
63
74
  end
64
75
  end
65
76
  end