polyfill 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce45400dde62a6c4481017080a3770fe3557619e
4
- data.tar.gz: 29d853335b679ed69d51df345786021e8919b121
3
+ metadata.gz: 3b944cddd5bba115b1c21189a683eebfb41d3e85
4
+ data.tar.gz: d1069d216c3850bbb3687c1f39251403150c6912
5
5
  SHA512:
6
- metadata.gz: 2f9a80ce2cc37783a1060d403317eb5e142c6c1a97a81057fc4123c9c7d8e7fcf6fcbec1f40d130d43ef8ad737df0db2f55c09b62f2a10de674d815d88b01f2d
7
- data.tar.gz: e465ec4b46c0ba099cfd5121402e6366eeca20991f6c00d03656127b0cfb6fe36159f5fd87d955655282e0bc076025d69a1622e10357f81996c7e3bd2ec6525b
6
+ metadata.gz: 4b8fa7d1486148b1b305244ec0002fec739faa019e437f5163738ba0055d9ce0fe1ee1548a48fddc19ef628bdfada326b8fac6031ff5fda4497119943a54936b
7
+ data.tar.gz: 5f6f3e9a641cc20f9e9d06c420506b55084b1b379da2a90bd3509ea35f107422126bc8084edd22a1bcad2f0ba7706c6d4962439895450d934da18f8a7a51914c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ # [0.9.0][] (2017-05-05)
2
+
3
+ ## Added
4
+
5
+ - v2.2 Enumerable#max
6
+ - v2.2 Enumerable#max_by
7
+ - v2.2 Enumerable#min
8
+ - v2.2 Enumerable#min_by
9
+ - v2.2 Vector#@+
10
+ - Polyfill.get can now be used with `prepend`
11
+
12
+ ## Fixed
13
+
14
+ - Enumerable should add to Matrix and Vector as well
15
+
1
16
  # [0.8.0][] (2017-04-27)
2
17
 
3
18
  ## Changed
@@ -141,6 +156,7 @@
141
156
  - v2.4 String#concat?
142
157
  - v2.4 String#prepend?
143
158
 
159
+ [0.9.0]: https://github.com/AaronLasseigne/polyfill/compare/v0.8.0...v0.9.0
144
160
  [0.8.0]: https://github.com/AaronLasseigne/polyfill/compare/v0.7.0...v0.8.0
145
161
  [0.7.0]: https://github.com/AaronLasseigne/polyfill/compare/v0.6.0...v0.7.0
146
162
  [0.6.0]: https://github.com/AaronLasseigne/polyfill/compare/v0.5.0...v0.6.0
data/README.md CHANGED
@@ -33,7 +33,7 @@ See the [implementation table](#implementation-table) for specifics about what h
33
33
  Add it to your Gemfile:
34
34
 
35
35
  ```ruby
36
- gem 'polyfill', '0.8.0'
36
+ gem 'polyfill', '0.9.0'
37
37
  ```
38
38
 
39
39
  Or install it manually:
@@ -95,7 +95,7 @@ using Polyfill(native: true, Numeric: :all)
95
95
  Prior to Ruby 2.4, refinements do not work on Modules. When using a polyfill
96
96
  on a module it will instead refine the core classes that use the module. If
97
97
  you're building your own class, it will not receive the polyfill. Instead,
98
- you can `include` (or `extend`) in a polyfill with `Polyfill.get`.
98
+ you can `include` (or `extend` or `prepend`) in a polyfill with `Polyfill.get`.
99
99
 
100
100
  ```ruby
101
101
  class Foo
@@ -316,10 +316,10 @@ end
316
316
  | Binding | #local_variables | No |
317
317
  | | #receiver | No |
318
318
  | Dir | #fileno | No |
319
- | Enumerable | #max | No |
320
- | | #max_by | No |
321
- | | #min | No |
322
- | | #min_by | No |
319
+ | Enumerable | #max | Yes |
320
+ | | #max_by | Yes |
321
+ | | #min | Yes |
322
+ | | #min_by | Yes |
323
323
  | | #slice_after | Yes |
324
324
  | | #slice_when | Yes |
325
325
  | Etc | .confstr | No |
@@ -371,7 +371,7 @@ end
371
371
  | TSort | .each_strongly_connected_component | No |
372
372
  | | .each_strongly_connected_component_from | No |
373
373
  | | .tsort_each | No |
374
- | Vector | #+@ | No |
374
+ | Vector | #+@ | Yes |
375
375
  | | #-@ | No |
376
376
  | | #angle_with | No |
377
377
  | | .basis | No |
data/lib/polyfill.rb CHANGED
@@ -1,31 +1,18 @@
1
- require 'ipaddr'
2
- require 'stringio'
3
1
  require 'polyfill/version'
4
- require 'polyfill/utils'
2
+ require 'polyfill/internal_utils'
5
3
 
6
4
  module Polyfill
7
- module Parcel; end
5
+ module Module; end
8
6
 
9
7
  def get(module_name, methods, options = {})
10
- if Object.const_get(module_name.to_s).is_a?(Class)
8
+ if Object.const_get(module_name.to_s, false).is_a?(Class)
11
9
  raise ArgumentError, "#{module_name} is a class not a module"
12
10
  end
13
11
 
14
12
  #
15
13
  # parse options
16
14
  #
17
- versions = {
18
- '2.2' => Polyfill::V2_2,
19
- '2.3' => Polyfill::V2_3,
20
- '2.4' => Polyfill::V2_4
21
- }
22
- desired_version = options.delete(:version) || versions.keys.max
23
- unless versions.keys.include?(desired_version)
24
- raise ArgumentError, "invalid value for keyword version: #{desired_version}"
25
- end
26
- versions.reject! do |version_number, _|
27
- version_number > desired_version
28
- end
15
+ versions = InternalUtils.polyfill_versions_to_use(options.delete(:version))
29
16
 
30
17
  unless options.empty?
31
18
  raise ArgumentError, "unknown keyword: #{options.first[0]}"
@@ -34,75 +21,47 @@ module Polyfill
34
21
  #
35
22
  # find all polyfills for the module across all versions
36
23
  #
37
- module_names = module_name.to_s.split('::')
38
- current_ruby_version = RUBY_VERSION[/\A(\d+\.\d+)/, 1]
39
-
40
- modules_with_updates = []
41
- modules = []
42
- versions.each do |version_number, version_module|
43
- begin
44
- final_module = module_names
45
- .reduce(version_module) do |current_mod, name|
46
- current_mod.const_get(name, false)
47
- end
48
-
49
- modules_with_updates << final_module
50
-
51
- next if version_number <= current_ruby_version
52
-
53
- modules << final_module.clone
54
- rescue NameError
55
- nil
56
- end
57
- end
58
-
59
- if modules_with_updates.empty?
60
- raise ArgumentError, %Q("#{module_name}" has no updates)
61
- end
24
+ modules_with_updates, modules = InternalUtils.modules_to_use(module_name, versions)
62
25
 
63
26
  #
64
27
  # remove methods that were not requested
65
28
  #
66
- methods_with_updates = modules_with_updates.flat_map(&:instance_methods).uniq
67
- requested_methods = methods == :all ? methods_with_updates : methods
68
-
69
- unless (leftovers = (requested_methods - methods_with_updates)).empty?
70
- raise ArgumentError, %Q("##{leftovers.first}" is not a valid method on #{module_name} or has no updates)
71
- end
29
+ requested_methods = InternalUtils.methods_to_keep(modules_with_updates, methods, '#', module_name)
72
30
 
73
31
  modules.each do |instance_module|
74
- instance_module.instance_methods.each do |name|
75
- instance_module.send(:remove_method, name) unless requested_methods.include?(name)
76
- end
32
+ InternalUtils.keep_only_these_methods!(instance_module, requested_methods)
77
33
  end
78
34
 
79
35
  #
80
36
  # build the module to return
81
37
  #
82
- mod = Module.new
38
+ InternalUtils.create_module do |mod|
39
+ # make sure the methods get added if this module is included
40
+ mod.singleton_class.send(:define_method, :included) do |base|
41
+ modules.each do |module_to_add|
42
+ base.include module_to_add unless module_to_add.instance_methods.empty?
43
+ end
44
+ end
83
45
 
84
- # make sure the methods get added if this module is included
85
- mod.singleton_class.send(:define_method, :included) do |base|
86
- modules.each do |module_to_add|
87
- base.include module_to_add unless module_to_add.instance_methods.empty?
46
+ # make sure the methods get added if this module is extended
47
+ mod.singleton_class.send(:define_method, :extended) do |base|
48
+ modules.each do |module_to_add|
49
+ base.extend module_to_add unless module_to_add.instance_methods.empty?
50
+ end
88
51
  end
89
- end
90
52
 
91
- # make sure the methods get added if this module is extended
92
- mod.singleton_class.send(:define_method, :extended) do |base|
93
- modules.each do |module_to_add|
94
- base.extend module_to_add unless module_to_add.instance_methods.empty?
53
+ # make sure the methods get added if this module is prepended
54
+ mod.singleton_class.send(:define_method, :prepended) do |base|
55
+ modules.each do |module_to_add|
56
+ base.prepend module_to_add unless module_to_add.instance_methods.empty?
57
+ end
95
58
  end
96
59
  end
97
-
98
- Polyfill::Parcel.const_set("O#{mod.object_id}", mod)
99
60
  end
100
61
  module_function :get
101
62
  end
102
63
 
103
64
  def Polyfill(options = {}) # rubocop:disable Style/MethodName
104
- mod = Module.new
105
-
106
65
  #
107
66
  # parse options
108
67
  #
@@ -116,21 +75,12 @@ def Polyfill(options = {}) # rubocop:disable Style/MethodName
116
75
  0
117
76
  end
118
77
  end
119
- others = others.to_h
120
-
121
- versions = {
122
- '2.2' => Polyfill::V2_2,
123
- '2.3' => Polyfill::V2_3,
124
- '2.4' => Polyfill::V2_4
125
- }
126
- desired_version = others.delete(:version) || versions.keys.max
127
- unless versions.keys.include?(desired_version)
128
- raise ArgumentError, "invalid value for keyword version: #{desired_version}"
129
- end
130
- versions.reject! do |version_number, _|
131
- version_number > desired_version
78
+ objects.each do |object_name, _|
79
+ Object.const_get(object_name.to_s, false)
132
80
  end
81
+ others = others.to_h
133
82
 
83
+ versions = Polyfill::InternalUtils.polyfill_versions_to_use(others.delete(:version))
134
84
  native = others.delete(:native) { false }
135
85
 
136
86
  unless others.empty?
@@ -138,160 +88,136 @@ def Polyfill(options = {}) # rubocop:disable Style/MethodName
138
88
  end
139
89
 
140
90
  #
141
- # useful var
91
+ # build the module to return
142
92
  #
143
- current_ruby_version = RUBY_VERSION[/\A(\d+\.\d+)/, 1]
144
-
145
- objects.each do |full_name, methods|
146
- #
147
- # find all polyfills for the object across all versions
148
- #
149
- object_module_names = full_name.to_s.split('::')
150
-
151
- object_modules = versions
152
- .map do |version_number, version_module|
93
+ Polyfill::InternalUtils.create_module do |mod|
94
+ objects.each do |object_name, methods|
95
+ #
96
+ # find all polyfills for the object across all versions
97
+ #
98
+ modules_with_updates, instance_modules = Polyfill::InternalUtils.modules_to_use(object_name, versions)
99
+
100
+ class_modules_with_updates = modules_with_updates.map do |module_with_updates|
153
101
  begin
154
- final_module = object_module_names
155
- .reduce(version_module) do |current_mod, name|
156
- current_mod.const_get(name, false)
157
- end
158
-
159
- [version_number, final_module]
102
+ module_with_updates.const_get(:ClassMethods, false)
160
103
  rescue NameError
161
104
  nil
162
105
  end
163
- end
164
- .compact
165
-
166
- if object_modules.empty?
167
- raise ArgumentError, %Q("#{full_name}" is not a valid object or has no updates)
168
- end
106
+ end.compact
107
+ class_modules = instance_modules.map do |module_with_updates|
108
+ begin
109
+ module_with_updates.const_get(:ClassMethods, false).clone
110
+ rescue NameError
111
+ nil
112
+ end
113
+ end.compact
169
114
 
170
- #
171
- # get all class modules and instance modules from the polyfills
172
- #
173
- class_modules = object_modules.map do |version_number, object_module|
174
- begin
175
- [version_number, object_module.const_get(:ClassMethods, false).clone]
176
- rescue NameError
177
- nil
115
+ #
116
+ # get all requested class and instance methods
117
+ #
118
+ if methods != :all && (method_name = methods.find { |method| method !~ /\A[.#]/ })
119
+ raise ArgumentError, %Q("#{method_name}" must start with a "." if it's a class method or "#" if it's an instance method)
178
120
  end
179
- end.compact
180
- instance_modules = object_modules.map do |version_number, object_module|
181
- [version_number, object_module.clone]
182
- end
183
-
184
- #
185
- # get all requested class and instance methods
186
- #
187
- if methods != :all && (method_name = methods.find { |method| method !~ /\A[.#]/ })
188
- raise ArgumentError, %Q("#{method_name}" must start with a "." if it's a class method or "#" if it's an instance method)
189
- end
190
121
 
191
- all_methods_for = lambda do |modules|
192
- modules.flat_map { |_, m| m.instance_methods }.uniq
193
- end
194
- available_class_methods = all_methods_for.call(class_modules)
195
- available_instance_methods = all_methods_for.call(instance_modules)
196
-
197
- select_and_clean = lambda do |leader|
198
- methods.select { |method| method.start_with?(leader) }.map { |method| method[1..-1].to_sym }
199
- end
200
- requested_class_methods = methods == :all ? available_class_methods : select_and_clean.call('.')
201
- requested_instance_methods = methods == :all ? available_instance_methods : select_and_clean.call('#')
202
-
203
- unless (leftovers = (requested_class_methods - available_class_methods)).empty?
204
- raise ArgumentError, %Q(".#{leftovers.first}" is not a valid method on #{full_name} or has no updates)
205
- end
206
- unless (leftovers = (requested_instance_methods - available_instance_methods)).empty?
207
- raise ArgumentError, %Q("##{leftovers.first}" is not a valid method on #{full_name} or has no updates)
208
- end
122
+ instance_methods, class_methods =
123
+ if methods == :all
124
+ [:all, :all]
125
+ else
126
+ methods
127
+ .partition { |m| m.start_with?('#') }
128
+ .map { |method_list| method_list.map { |name| name[1..-1].to_sym } }
129
+ end
209
130
 
210
- #
211
- # get the class(es) to refine
212
- #
213
- base_class = object_modules.first.last.name.sub(/\APolyfill::V\d_\d::/, '')
214
- base_classes =
215
- case base_class
216
- when 'Comparable'
217
- %w[Numeric String Time]
218
- when 'Enumerable'
219
- %w[Array Dir Enumerator Hash IO Range StringIO Struct]
220
- when 'Kernel'
221
- %w[Object]
222
- else
223
- [base_class]
131
+ requested_instance_methods =
132
+ Polyfill::InternalUtils.methods_to_keep(modules_with_updates, instance_methods, '#', object_name)
133
+ requested_class_methods =
134
+ Polyfill::InternalUtils.methods_to_keep(class_modules_with_updates, class_methods, '.', object_name)
135
+
136
+ #
137
+ # get the class(es) to refine
138
+ #
139
+ base_object = object_name.to_s
140
+ base_objects =
141
+ case base_object
142
+ when 'Comparable'
143
+ %w[Numeric String Time]
144
+ when 'Enumerable'
145
+ %w[Array Dir Enumerator Hash IO Matrix Range StringIO Struct Vector]
146
+ when 'Kernel'
147
+ %w[Object]
148
+ else
149
+ [base_object]
150
+ end
151
+ base_objects.select! do |klass|
152
+ begin
153
+ Object.const_get(klass, false)
154
+ rescue NameError
155
+ false
156
+ end
224
157
  end
225
158
 
226
- #
227
- # refine in class methods
228
- #
229
- class_modules.each do |version_number, class_module|
230
- next if version_number <= current_ruby_version
159
+ #
160
+ # refine in class methods
161
+ #
162
+ class_modules.each do |class_module|
163
+ Polyfill::InternalUtils.keep_only_these_methods!(class_module, requested_class_methods)
231
164
 
232
- class_module.instance_methods.each do |name|
233
- class_module.send(:remove_method, name) unless requested_class_methods.include?(name)
234
- end
165
+ next if class_module.instance_methods.empty?
235
166
 
236
- next if class_module.instance_methods.empty?
167
+ mod.module_exec(requested_class_methods) do |methods_added|
168
+ base_objects.each do |klass|
169
+ refine Object.const_get(klass, false).singleton_class do
170
+ include class_module
237
171
 
238
- mod.module_exec(requested_class_methods) do |methods_added|
239
- base_classes.each do |klass|
240
- refine Object.const_get(klass).singleton_class do
241
- include class_module
172
+ if native
173
+ Polyfill::InternalUtils.ignore_warnings do
174
+ define_method :respond_to? do |name, include_all = false|
175
+ return true if methods_added.include?(name)
242
176
 
243
- if native
244
- Polyfill::Utils.ignore_warnings do
245
- define_method :respond_to? do |name, include_all = false|
246
- return true if methods_added.include?(name)
177
+ super(name, include_all)
178
+ end
247
179
 
248
- super(name, include_all)
249
- end
180
+ define_method :__send__ do |name, *args, &block|
181
+ return super(name, *args, &block) unless methods_added.include?(name)
250
182
 
251
- define_method :__send__ do |name, *args, &block|
252
- return super(name, *args, &block) unless methods_added.include?(name)
253
-
254
- class_module.instance_method(name).bind(self).call(*args, &block)
183
+ class_module.instance_method(name).bind(self).call(*args, &block)
184
+ end
185
+ alias_method :send, :__send__
255
186
  end
256
- alias_method :send, :__send__
257
187
  end
258
188
  end
259
189
  end
260
190
  end
261
191
  end
262
- end
263
-
264
- #
265
- # refine in instance methods
266
- #
267
- instance_modules.each do |version_number, instance_module|
268
- next if version_number <= current_ruby_version
269
192
 
270
- instance_module.instance_methods.each do |name|
271
- instance_module.send(:remove_method, name) unless requested_instance_methods.include?(name)
272
- end
193
+ #
194
+ # refine in instance methods
195
+ #
196
+ instance_modules.each do |instance_module|
197
+ Polyfill::InternalUtils.keep_only_these_methods!(instance_module, requested_instance_methods)
273
198
 
274
- next if instance_module.instance_methods.empty?
199
+ next if instance_module.instance_methods.empty?
275
200
 
276
- mod.module_exec(requested_instance_methods) do |methods_added|
277
- base_classes.each do |klass|
278
- refine Object.const_get(klass) do
279
- include instance_module
201
+ mod.module_exec(requested_instance_methods) do |methods_added|
202
+ base_objects.each do |klass|
203
+ refine Object.const_get(klass, false) do
204
+ include instance_module
280
205
 
281
- if native
282
- Polyfill::Utils.ignore_warnings do
283
- define_method :respond_to? do |name, include_all = false|
284
- return super(name, include_all) unless methods_added.include?(name)
206
+ if native
207
+ Polyfill::InternalUtils.ignore_warnings do
208
+ define_method :respond_to? do |name, include_all = false|
209
+ return super(name, include_all) unless methods_added.include?(name)
285
210
 
286
- true
287
- end
211
+ true
212
+ end
288
213
 
289
- define_method :__send__ do |name, *args, &block|
290
- return super(name, *args, &block) unless methods_added.include?(name)
214
+ define_method :__send__ do |name, *args, &block|
215
+ return super(name, *args, &block) unless methods_added.include?(name)
291
216
 
292
- instance_module.instance_method(name).bind(self).call(*args, &block)
217
+ instance_module.instance_method(name).bind(self).call(*args, &block)
218
+ end
219
+ alias_method :send, :__send__
293
220
  end
294
- alias_method :send, :__send__
295
221
  end
296
222
  end
297
223
  end
@@ -299,8 +225,6 @@ def Polyfill(options = {}) # rubocop:disable Style/MethodName
299
225
  end
300
226
  end
301
227
  end
302
-
303
- Polyfill::Parcel.const_set("O#{mod.object_id}", mod)
304
228
  end
305
229
 
306
230
  require 'polyfill/v2_2'
@@ -0,0 +1,93 @@
1
+ module Polyfill
2
+ module InternalUtils
3
+ VERSIONS = {
4
+ '2.2' => 'V2_2',
5
+ '2.3' => 'V2_3',
6
+ '2.4' => 'V2_4'
7
+ }.freeze
8
+ private_constant :VERSIONS
9
+
10
+ def current_ruby_version
11
+ @current_ruby_version ||= RUBY_VERSION[/\A(\d+\.\d+)/, 1]
12
+ end
13
+ module_function :current_ruby_version
14
+
15
+ def ignore_warnings
16
+ orig = $VERBOSE
17
+ $VERBOSE = nil
18
+
19
+ yield
20
+
21
+ $VERBOSE = orig
22
+ end
23
+ module_function :ignore_warnings
24
+
25
+ def polyfill_versions_to_use(desired_version = nil)
26
+ desired_version = VERSIONS.keys.max if desired_version.nil?
27
+
28
+ unless VERSIONS.keys.include?(desired_version)
29
+ raise ArgumentError, "invalid value for keyword version: #{desired_version}"
30
+ end
31
+
32
+ VERSIONS
33
+ .reject { |version, _| version > desired_version }
34
+ .map { |version, mod| [version, Polyfill.const_get(mod, false)] }
35
+ .to_h
36
+ end
37
+ module_function :polyfill_versions_to_use
38
+
39
+ def keep_only_these_methods!(mod, whitelist)
40
+ mod.instance_methods.each do |name|
41
+ mod.send(:remove_method, name) unless whitelist.include?(name)
42
+ end
43
+ end
44
+ module_function :keep_only_these_methods!
45
+
46
+ def modules_to_use(module_name, versions)
47
+ modules_with_updates = []
48
+ modules = []
49
+
50
+ versions.each do |version_number, version_module|
51
+ begin
52
+ final_module = version_module.const_get(module_name.to_s, false)
53
+
54
+ modules_with_updates << final_module
55
+
56
+ next if version_number <= InternalUtils.current_ruby_version
57
+
58
+ modules << final_module.clone
59
+ rescue NameError
60
+ nil
61
+ end
62
+ end
63
+
64
+ if modules_with_updates.empty?
65
+ raise ArgumentError, %Q("#{module_name}" has no updates)
66
+ end
67
+
68
+ [modules_with_updates, modules]
69
+ end
70
+ module_function :modules_to_use
71
+
72
+ def methods_to_keep(modules, methods, lead_symbol, module_name)
73
+ methods_with_updates = modules.flat_map(&:instance_methods).uniq
74
+ requested_methods = methods == :all ? methods_with_updates : methods
75
+
76
+ unless (leftovers = (requested_methods - methods_with_updates)).empty?
77
+ raise ArgumentError, %Q("#{lead_symbol}#{leftovers.first}" is not a valid method on #{module_name} or has no updates)
78
+ end
79
+
80
+ requested_methods
81
+ end
82
+ module_function :methods_to_keep
83
+
84
+ def create_module
85
+ mod = ::Module.new
86
+
87
+ yield(mod)
88
+
89
+ Polyfill::Module.const_set("M#{mod.object_id}", mod)
90
+ end
91
+ module_function :create_module
92
+ end
93
+ end
data/lib/polyfill/v2_2.rb CHANGED
@@ -1,9 +1,8 @@
1
1
  require_relative 'v2_2/enumerable'
2
2
  require_relative 'v2_2/kernel'
3
+ require_relative 'v2_2/vector'
3
4
 
4
5
  module Polyfill
5
6
  module V2_2
6
- include Enumerable
7
- include Kernel
8
7
  end
9
8
  end
@@ -1,6 +1,42 @@
1
1
  module Polyfill
2
2
  module V2_2
3
3
  module Enumerable
4
+ def max(n = nil)
5
+ return block_given? ? super(&::Proc.new) : super() if n.nil? || n == 1
6
+
7
+ raise ArgumentError, "negative size (#{n})" if n < 0
8
+
9
+ (block_given? ? sort(&::Proc.new) : sort).last(n).reverse
10
+ end
11
+
12
+ def max_by(n = nil)
13
+ if n.nil? || n == 1 || !block_given?
14
+ return block_given? ? super(&::Proc.new) : super()
15
+ end
16
+
17
+ raise ArgumentError, "negative size (#{n})" if n < 0
18
+
19
+ sort_by(&::Proc.new).last(n).reverse
20
+ end
21
+
22
+ def min(n = nil)
23
+ return block_given? ? super(&::Proc.new) : super() if n.nil? || n == 1
24
+
25
+ raise ArgumentError, "negative size (#{n})" if n < 0
26
+
27
+ (block_given? ? sort(&::Proc.new) : sort).first(n)
28
+ end
29
+
30
+ def min_by(n = nil)
31
+ if n.nil? || n == 1 || !block_given?
32
+ return block_given? ? super(&::Proc.new) : super()
33
+ end
34
+
35
+ raise ArgumentError, "negative size (#{n})" if n < 0
36
+
37
+ sort_by(&::Proc.new).first(n)
38
+ end
39
+
4
40
  def slice_after(pattern = nil)
5
41
  raise ArgumentError, 'both pattern and block are given' if pattern && block_given?
6
42
  raise ArgumentError, 'wrong number of arguments (given 0, expected 1)' if !pattern && !block_given?
@@ -0,0 +1,9 @@
1
+ module Polyfill
2
+ module V2_2
3
+ module Vector
4
+ def +@
5
+ self
6
+ end
7
+ end
8
+ end
9
+ end
data/lib/polyfill/v2_3.rb CHANGED
@@ -8,12 +8,5 @@ require_relative 'v2_3/struct'
8
8
 
9
9
  module Polyfill
10
10
  module V2_3
11
- include Array
12
- include Hash
13
- include Enumerable
14
- include Enumerator::Lazy
15
- include Kernel
16
- include String
17
- include Struct
18
11
  end
19
12
  end
data/lib/polyfill/v2_4.rb CHANGED
@@ -21,26 +21,5 @@ require_relative 'v2_4/pathname'
21
21
 
22
22
  module Polyfill
23
23
  module V2_4
24
- include Array
25
- include Comparable
26
- include Dir
27
- include Enumerable
28
- include Enumerator::Lazy
29
- include File
30
- include Float
31
- include Hash
32
- include Integer
33
- include IO
34
- include Kernel
35
- include MatchData
36
- include Numeric
37
- include Object
38
- include Regexp
39
- include String
40
- include StringIO
41
- include Symbol
42
-
43
- include IPAddr
44
- include Pathname
45
24
  end
46
25
  end
@@ -1,3 +1,3 @@
1
1
  module Polyfill
2
- VERSION = '0.8.0'.freeze
2
+ VERSION = '0.9.0'.freeze
3
3
  end
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.8.0
4
+ version: 0.9.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-04-27 00:00:00.000000000 Z
11
+ date: 2017-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,10 +86,11 @@ files:
86
86
  - bin/console
87
87
  - bin/setup
88
88
  - lib/polyfill.rb
89
- - lib/polyfill/utils.rb
89
+ - lib/polyfill/internal_utils.rb
90
90
  - lib/polyfill/v2_2.rb
91
91
  - lib/polyfill/v2_2/enumerable.rb
92
92
  - lib/polyfill/v2_2/kernel.rb
93
+ - lib/polyfill/v2_2/vector.rb
93
94
  - lib/polyfill/v2_3.rb
94
95
  - lib/polyfill/v2_3/array.rb
95
96
  - lib/polyfill/v2_3/enumerable.rb
@@ -1,13 +0,0 @@
1
- module Polyfill
2
- module Utils
3
- def ignore_warnings
4
- orig = $VERBOSE
5
- $VERBOSE = nil
6
-
7
- yield
8
-
9
- $VERBOSE = orig
10
- end
11
- module_function :ignore_warnings
12
- end
13
- end