polyfill 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b139f1e058fce855365397a2bbe902b2092da2a3a6e64e9326d6d136487a2e31
4
- data.tar.gz: e58e5b7b5ed9ee95375abfdc9f959730fbb4e900df86f5db11017a4241212a71
3
+ metadata.gz: dcf78a0e3232a09956c63e330dceee6477e1ca817175ca288f3c728564918a8b
4
+ data.tar.gz: 9d70ef2d07ba52b3105d8dd0a900a257f7a5c71b0a49e56b783e67d16441fba6
5
5
  SHA512:
6
- metadata.gz: 314f9d7bdd0385f0fb2682b9f4b1a2a2d30b967ee454a91c77aeeeeef651600a38a42642cc83b01c25197b7ae3e6180cbe91b45e7ebdf37713e9c305cfd0c384
7
- data.tar.gz: 4bf25f12ca82bb158353cc89994c46f04e0f183ba39e43c063d3195c7b5f486b00182912760daa4f6f5812d6f45ee6d282f03dac6a0cdc7e906aa428d035122a
6
+ metadata.gz: d7ddd097309f6a251144437baf7994baf8f15d85634137eb1cf880d4a119b57ab8c532a7bfad61523cb3e58c2f9802c5b06857985c7574dfa55b55ef4382be50
7
+ data.tar.gz: 5be3401b05404a346b7867ece1ef315a1acbddaa343df576803d3c8f84cf46dd2a746cefe957207ab70a89a997ef8fdfc12360329644a93f67ca7fa5310db7d7
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Master
2
2
 
3
+ # [1.2.0][] (2018-03-05)
4
+
5
+ ## Added
6
+
7
+ - v2.5 BigDecimal#clone
8
+ - v2.5 BigDecimal#dup
9
+ - v2.5 Dir.children
10
+ - v2.5 Dir.each_child
11
+ - v2.5 Integer.sqrt
12
+ - v2.5 Time.at
13
+ - v2.3 Prime.prime?
14
+ - v2.2 Math.log
15
+ - v2.2 Prime.prime?
16
+
3
17
  # [1.1.0][] (2018-02-23)
4
18
 
5
19
  ## Added
@@ -214,6 +228,7 @@ incorrect type was passed:
214
228
  - v2.4 String#concat?
215
229
  - v2.4 String#prepend?
216
230
 
231
+ [1.2.0]: https://github.com/AaronLasseigne/polyfill/compare/v1.1.0...v1.2.0
217
232
  [1.1.0]: https://github.com/AaronLasseigne/polyfill/compare/v1.0.1...v1.1.0
218
233
  [1.0.1]: https://github.com/AaronLasseigne/polyfill/compare/v1.0.0...v1.0.1
219
234
  [1.0.0]: https://github.com/AaronLasseigne/polyfill/compare/v0.10.0...v1.0.0
data/README.md CHANGED
@@ -27,7 +27,7 @@ monkey patching** that may cause issues outside of your use.
27
27
  Add it to your Gemfile:
28
28
 
29
29
  ```ruby
30
- gem 'polyfill', '~> 1.1'
30
+ gem 'polyfill', '~> 1.2'
31
31
  ```
32
32
 
33
33
  Or install it manually:
@@ -51,7 +51,7 @@ This project uses [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
51
51
  With the `Polyfill` method, you can polyfill methods for one or more Ruby
52
52
  objects. Each object is passed as a key. The value is an array of strings
53
53
  containing the methods you would like to polyfill. Instance methods need to
54
- start with '#' and class methods need to start with '.'.
54
+ start with "#" and class methods need to start with ".".
55
55
 
56
56
  ```ruby
57
57
  using Polyfill(
@@ -136,10 +136,10 @@ though they have techically changed. `FrozenError` is a subclass of
136
136
  |:-:| ---------------- | ------------------------ | ------- |
137
137
  | ✗ | Array | #append | New (alias for `push`)
138
138
  | ✗ | | #prepend | New (alias for `unshift`)
139
- | | BigDecimal | #clone | Returns the receiver itself instead of making a new instance.
140
- | | | #dup | Returns the receiver itself instead of making a new instance.
141
- | | Dir | .children | New
142
- | | | .each_child | New
139
+ | | BigDecimal | #clone | Returns the receiver itself instead of making a new instance.
140
+ | | | #dup | Returns the receiver itself instead of making a new instance.
141
+ | | Dir | .children | New
142
+ | | | .each_child | New
143
143
  | ✗ | | #glob | Accepts a new optional keyword argument, `:base`.
144
144
  | ✗ | Enumerable | #any? | Accepts a pattern argument.
145
145
  | ✗ | | #all? | Accepts a pattern argument.
@@ -165,7 +165,7 @@ though they have techically changed. `FrozenError` is a subclass of
165
165
  | ✓ | | #nobits? | New
166
166
  | ✗ | | #pow | Same as `**` but it accepts an optional modulo argument for calculating modular exponentiation.
167
167
  | ✓ | | #round | Always return an Integer.
168
- | | | .sqrt | New
168
+ | | | .sqrt | New
169
169
  | ✓ | | #truncate | Always return an Integer.
170
170
  | ✗ | IO | #pread | New
171
171
  | ✗ | | #pwrite | New
@@ -230,7 +230,7 @@ though they have techically changed. `FrozenError` is a subclass of
230
230
  | ✗ | Struct | .new | Accepts a new optional keyword argument, `:keyword_init`.
231
231
  | ✗ | Thread | #fetch | New
232
232
  | ✗ | | #name= | Description set by `Thread#name=` is now visible on Windows 10.
233
- | | Time | #at | Accepts a third argument which specifies the unit of the second argument.
233
+ | | Time | .at | Accepts a third argument which specifies the unit of the second argument.
234
234
  | ✗ | URI | .open | New (alias of `Kernel.open`)
235
235
  | ✗ | Zlib::GzipWriter | #write | Accepts multiple arguments.
236
236
 
@@ -249,59 +249,59 @@ though they have techically changed. `FrozenError` is a subclass of
249
249
  | ✗ | CSV | #new | Accepts a new optional keyword argument, `liberal_parsing`.
250
250
  | ✓ | Dir | .empty? | New
251
251
  | ✓ | Enumerable | #chunk | Calling without a block returns an enumerator.
252
- | ✓ | | #sum |
253
- | ✓ | | #uniq |
254
- | ✓ | Enumerator::Lazy | #chunk_while |
255
- | ✓ | | #uniq |
256
- | ✓ | File | .empty? |
257
- | ✗ | FileTest | .empty? |
252
+ | ✓ | | #sum | New
253
+ | ✓ | | #uniq | New
254
+ | ✓ | Enumerator::Lazy | #chunk_while | New
255
+ | ✓ | | #uniq | New
256
+ | ✓ | File | .empty? | New (alias of `zero?`)
257
+ | ✗ | FileTest | .empty? | New (alias of `zero?`)
258
258
  | ✓ | Float | #ceil | Accepts an optional digits argument.
259
259
  | ✓ | | #floor | Accepts an optional digits argument.
260
260
  | ✗ | | #round | Accepts an optional digits argument and provides a new optional keyword argument, `half`.
261
261
  | ✓ | | #truncate | Accepts an optional digits argument.
262
- | ✓ | Hash | #compact |
263
- | ✓ | | #compact! |
264
- | ✓ | | #transform_values |
265
- | ✓ | | #transform_values! |
262
+ | ✓ | Hash | #compact | New
263
+ | ✓ | | #compact! | New
264
+ | ✓ | | #transform_values | New
265
+ | ✓ | | #transform_values! | New
266
266
  | ✓ | Integer | #ceil | Accepts an optional digits argument.
267
- | ✓ | | #digits |
267
+ | ✓ | | #digits | New
268
268
  | ✓ | | #floor | Accepts an optional digits argument.
269
269
  | ✓ | | #round | Accepts an optional digits argument and provides a new optional keyword argument, `half`.
270
270
  | ✓ | | #truncate | Accepts an optional digits argument.
271
271
  | ✓ | IO | #each_line | Accepts a new optional keyword argument, `chomp`.
272
272
  | ✓ | | .foreach | Accepts a new optional keyword argument, `chomp`.
273
273
  | ✓ | | #gets | Accepts a new optional keyword argument, `chomp`.
274
- | ✓ | | #lines |
275
- | ✓ | | #readline |
276
- | ✓ | | #readlines |
274
+ | ✓ | | #lines | Accepts a new optional keyword argument, `chomp`.
275
+ | ✓ | | #readline | Accepts a new optional keyword argument, `chomp`.
276
+ | ✓ | | #readlines | Accepts a new optional keyword argument, `chomp`.
277
277
  | ✓ | | .readlines | Accepts a new optional keyword argument, `chomp`.
278
278
  | ✓ | IPAddr | #== | No longer raises an exception if coercion fails.
279
279
  | ✓ | | #<=> | No longer raises an exception if coercion fails.
280
280
  | ✗ | Kernel | #send | Supports refined methods.
281
- | ✗ | Logger | #new |
282
- | ✓ | MatchData | #named_captures |
281
+ | ✗ | Logger | #new | Allow specifying logger parameters in constructor such as `level`, `progname`, `datetime_format`, `formatter`. Add `shift_period_suffix` option.
282
+ | ✓ | MatchData | #named_captures | New
283
283
  | ✓ | | #values_at | Supports named captures.
284
284
  | ✗ | Module | #refine | Accepts a module as an argument.
285
- | ✗ | | .used_modules |
285
+ | ✗ | | .used_modules | New
286
286
  | ✗ | Net::HTTP | #post | New
287
287
  | ✗ | Net::FTP | #new | Supports hash style options.
288
288
  | ✗ | | #status | Accepts a new optional keyword argument, `pathname`.
289
- | ✓ | Numeric | #clone |
290
- | ✓ | | #dup |
291
- | ✓ | | #finite? |
292
- | ✓ | | #infinite? |
293
- | ✓ | Object | #clone |
294
- | ✗ | OptionParser | #order |
295
- | ✗ | | #order! |
296
- | ✗ | | #parse |
297
- | ✗ | | #parse! |
298
- | ✗ | | #permute |
299
- | ✗ | | #permute! |
300
- | ✓ | Pathname | #empty? |
301
- | ✗ | Readline | #quoting_detection_proc |
302
- | ✗ | | #quoting_detection_proc= |
289
+ | ✓ | Numeric | #clone | Returns self instead of raising an error.
290
+ | ✓ | | #dup | Returns self instead of raising an error.
291
+ | ✓ | | #finite? | New
292
+ | ✓ | | #infinite? | New
293
+ | ✓ | Object | #clone | Accepts a new optional keyword argument, `freeze`.
294
+ | ✗ | OptionParser | #order | Accepts a new optional keyword argument, `into`.
295
+ | ✗ | | #order! | Accepts a new optional keyword argument, `into`.
296
+ | ✗ | | #parse | Accepts a new optional keyword argument, `into`.
297
+ | ✗ | | #parse! | Accepts a new optional keyword argument, `into`.
298
+ | ✗ | | #permute | Accepts a new optional keyword argument, `into`.
299
+ | ✗ | | #permute! | Accepts a new optional keyword argument, `into`.
300
+ | ✓ | Pathname | #empty? | New
301
+ | ✗ | Readline | #quoting_detection_proc | New
302
+ | ✗ | | #quoting_detection_proc= | New
303
303
  | ✗ | REXML::Element | #[] | If `String` or `Symbol` is specified, attribute value is returned. Otherwise, Nth child is returned.
304
- | ✗ | Rational | #round |
304
+ | ✗ | Rational | #round | Accepts a new optional keyword argument, `half`.
305
305
  | ✓ | Regexp | #match? | New
306
306
  | ✗ | Set | #compare_by_identity | New
307
307
  | ✗ | | #compare_by_identity? | New
@@ -313,12 +313,12 @@ though they have techically changed. `FrozenError` is a subclass of
313
313
  | ✗ | | #downcase! | Supports Unicode and accepts several new keyword arguments.
314
314
  | ✓ | | #each_line | Accepts a new optional keyword argument, `chomp`.
315
315
  | ✓ | | #lines | Accepts a new optional keyword argument, `chomp`.
316
- | ✓ | | #match? |
316
+ | ✓ | | #match? | New
317
317
  | P | | .new | Accepts a new optional keyword argument, `capacity`. **Differences:** Allows `:capacity` option to pass but does nothing with it.
318
318
  | ✓ | | #prepend | Now accepts multiple arguments.
319
319
  | ✗ | | #swapcase | Supports Unicode and accepts several new keyword arguments.
320
320
  | ✗ | | #swapcase! | Supports Unicode and accepts several new keyword arguments.
321
- | ✓ | | #unpack1 |
321
+ | ✓ | | #unpack1 | New
322
322
  | ✗ | | #upcase | Supports Unicode and accepts several new keyword arguments.
323
323
  | ✗ | | #upcase! | Supports Unicode and accepts several new keyword arguments.
324
324
  | ✓ | StringIO | #each_line | Accepts a new optional keyword argument, `chomp`.
@@ -330,16 +330,18 @@ though they have techically changed. `FrozenError` is a subclass of
330
330
  | P | | #casecmp? | New **Differences:** Does not support Unicode characters.
331
331
  | ✗ | | #downcase | Supports Unicode and accepts several new keyword arguments.
332
332
  | ✗ | | #downcase! | Supports Unicode and accepts several new keyword arguments.
333
- | ✓ | | #match |
334
- | ✓ | | #match? |
333
+ | ✓ | | #match | Now returns `MatchData` instead of match position.
334
+ | ✓ | | #match? | New
335
335
  | ✗ | | #swapcase | Supports Unicode and accepts several new keyword arguments.
336
336
  | ✗ | | #swapcase! | Supports Unicode and accepts several new keyword arguments.
337
- | ✗ | | #to_proc |
337
+ | ✗ | | #to_proc | Supports refinements.
338
338
  | ✗ | | #upcase | Supports Unicode and accepts several new keyword arguments.
339
339
  | ✗ | | #upcase! | Supports Unicode and accepts several new keyword arguments.
340
- | ✗ | Thread | #report\_on\_exception |
341
- | ✗ | | .report\_on\_exception |
342
- | ✗ | TracePoint | #callee_id |
340
+ | ✗ | Thread | #report\_on\_exception | New
341
+ | ✗ | | #report\_on\_exception= | New
342
+ | ✗ | | .report\_on\_exception | New
343
+ | ✗ | | .report\_on\_exception= | New
344
+ | ✗ | TracePoint | #callee_id | New
343
345
  | ✗ | Warning | #warn | New
344
346
 
345
347
  ### 2.3
@@ -347,7 +349,7 @@ though they have techically changed. `FrozenError` is a subclass of
347
349
  | | Object | Method | Changes |
348
350
  |:-:| ----------------------- | ------------------------ | ------- |
349
351
  | ✗ | ARGF | #read_nonblock | Accepts a new optional keyword argument, `exception`.
350
- | ✗ | Array | #bsearch_index |
352
+ | ✗ | Array | #bsearch_index | New
351
353
  | ✓ | | #dig | New
352
354
  | ✗ | | #flatten | No longer calls `to_ary` on elements beyond the given level.
353
355
  | ✗ | | #flatten! | No longer calls `to_ary` on elements beyond the given level.
@@ -362,18 +364,18 @@ though they have techically changed. `FrozenError` is a subclass of
362
364
  | ✗ | Comparable | #== | No longer rescues exceptions.
363
365
  | ✗ | Coverage | .peek_result | New
364
366
  | ✗ | Enumerable | #chunk | No longer accepts the `initial_state` keyword argument.
365
- | ✓ | | #chunk_while |
367
+ | ✓ | | #chunk_while | New
366
368
  | ✓ | | #grep_v | New
367
369
  | ✓ | | #slice_before | No longer accepts the `initial_state` keyword argument.
368
370
  | ✓ | Enumerator::Lazy | #grep_v | New
369
- | ✗ | File | .mkfifo |
371
+ | ✗ | File | .mkfifo | New
370
372
  | ✗ | File::Stat | #ino | On Windows, it always returned `0`, but now returns `BY_HANDLE_FILE_INFORMATION.nFileIndexHigh/Low`.
371
- | ✗ | Hash | #< |
372
- | ✗ | | #<= |
373
- | ✗ | | #> |
374
- | ✗ | | #>= |
373
+ | ✗ | Hash | #< | New
374
+ | ✗ | | #<= | New
375
+ | ✗ | | #> | New
376
+ | ✗ | | #>= | New
375
377
  | ✓ | | #dig | New
376
- | ✓ | | #fetch_values |
378
+ | ✓ | | #fetch_values | New
377
379
  | ✗ | | #inspect | No longer raises an error if its content returns a string which is not compatible with `Encoding.default_external`.
378
380
  | P | | #to_proc | New **Differences:** 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)
379
381
  | ✗ | IO | #advise | No longer raises Errno::ENOSYS in cases where it was detected at build time but not available at runtime.
@@ -381,10 +383,10 @@ though they have techically changed. `FrozenError` is a subclass of
381
383
  | ✗ | | #each_codepoint | Raises an exception at incomplete character before EOF when conversion takes place.
382
384
  | ✗ | | #wait_readable | No longer checks FIONREAD.
383
385
  | ✓ | Kernel | #loop | When stopped by a StopIteration exception, returns what the enumerator has returned instead of nil.
384
- | ✗ | Logger | #level= |
386
+ | ✗ | Logger | #level= | New
385
387
  | ✗ | | #reopen | New
386
388
  | ✗ | Module | #define_method | Now requires a method body, `Proc`, `Method`, or a block.
387
- | ✗ | | #deprecate_constant |
389
+ | ✗ | | #deprecate_constant | New
388
390
  | ✗ | NameError | #receiver | New
389
391
  | ✗ | Net::FTP | .default_passive= | New
390
392
  | ✗ | | #mlst | New
@@ -400,9 +402,10 @@ though they have techically changed. `FrozenError` is a subclass of
400
402
  | ✗ | | .internal_super_of | New
401
403
  | ✗ | OpenSSL::SSL::SSLSocket | #accept_nonblock | Accepts a new keyword argument, `exception`.
402
404
  | ✗ | | #connect_nonblock | Accepts a new keyword argument, `exception`.
403
- | ✗ | Pathname | #ascend |
404
- | ✗ | | #descend |
405
- | | Queue | #close |
405
+ | ✗ | Pathname | #ascend | Returns an enumerator if no block is given.
406
+ | ✗ | | #descend | Returns an enumerator if no block is given.
407
+ | | Prime | .prime? | `ArgumentError` message says that an integer is expected instead of it being a comparison error.
408
+ | ✗ | Queue | #close | New
406
409
  | ✗ | Socket | #accept_nonblock | Accepts a new keyword argument, `exception`.
407
410
  | ✗ | | #connect_nonblock | Accepts a new keyword argument, `exception`.
408
411
  | ✓ | String | #+@ | New
@@ -440,16 +443,16 @@ though they have techically changed. `FrozenError` is a subclass of
440
443
  | ✗ | | #birthtime | New
441
444
  | ✗ | File::Stat | #birthtime | New
442
445
  | ✗ | Find | .find | Accepts a new optional keyword argument, `ignore_error`.
443
- | ✗ | GC | .latest_gc_info |
444
- | ✗ | | .stat |
445
- | ✗ | IO | #each_codepoint |
446
+ | ✗ | GC | .latest_gc_info | Returns `:state` to represent current GC status.
447
+ | ✗ | | .stat | Some keys were renamed and new keys were added.
448
+ | ✗ | IO | #each_codepoint | Raises an exception at incomplete character before EOF when conversion takes place.
446
449
  | ✗ | | #nonblock_read | Supports pipes on Windows.
447
450
  | ✗ | | #nonblock_write | Supports pipes on Windows.
448
451
  | ✗ | | #pathconf | New
449
452
  | ✓ | Kernel | #itself | New
450
453
  | ✗ | | #throw | Raises `UncaughtThrowError`, subclass of `ArgumentError` when there is no corresponding catch block, instead of `ArgumentError`.
451
454
  | ✗ | Math | .atan2 | Now returns values like as expected by C99 if both two arguments are infinity.
452
- | | | .log | Now raises `Math::DomainError` instead of returning `NaN` if the base is less than 0, and returns `NaN` instead of -infinity if both of two arguments are 0.
455
+ | | | .log | Now raises `Math::DomainError` instead of returning `NaN` if the base is less than 0, and returns `NaN` instead of -infinity if both of two arguments are 0.
453
456
  | ✗ | Matrix | #+@ | New
454
457
  | ✗ | | #-@ | New
455
458
  | ✗ | | #adjugate | New
@@ -462,16 +465,16 @@ though they have techically changed. `FrozenError` is a subclass of
462
465
  | ✗ | | #vstack | New
463
466
  | ✗ | Method | #curry | New
464
467
  | ✗ | | #super_method | New
465
- | ✗ | ObjectSpace | .memsize_of |
468
+ | ✗ | ObjectSpace | .memsize_of | Returns a size including sizeof(RVALUE).
466
469
  | ✗ | Pathname | #/ | New (alias of `#+`)
467
470
  | ✗ | | #birthtime | New
468
471
  | ✗ | | #find | Accepts a new optional keyword argument, `ignore_error`.
469
- | | Prime | .prime? | Now returns `false` for negative numbers.
470
- | ✗ | Process | .spawn |
472
+ | | Prime | .prime? | Now returns `false` for negative numbers.
473
+ | ✗ | Process | .spawn | Opens the file in write mode for redirect from `[:out, :err]`.
471
474
  | ✗ | String | #unicode_normalize | New
472
475
  | ✗ | | #unicode_normalize! | New
473
476
  | ✗ | | #unicode_normalized? | New
474
- | ✗ | Time | .httpdate |
477
+ | ✗ | Time | .httpdate | Always produces a UTC `Time` object.
475
478
  | ✗ | | .parse | May produce fixed-offset `Time` objects.
476
479
  | ✗ | | .rfc2822 | May produce fixed-offset `Time` objects.
477
480
  | ✗ | | .strptime | May produce fixed-offset `Time` objects. Raises `ArgumentError` when there is no date information.
@@ -108,5 +108,14 @@ module Polyfill
108
108
  obj.to_int
109
109
  end
110
110
  module_function :to_int
111
+
112
+ def to_f(obj)
113
+ unless obj.respond_to?(:to_f)
114
+ raise TypeError, "no implicit conversion of #{obj.class} into Float"
115
+ end
116
+
117
+ obj.to_f
118
+ end
119
+ module_function :to_f
111
120
  end
112
121
  end
data/lib/polyfill/v2_2.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  require_relative 'v2_2/enumerable'
2
2
  require_relative 'v2_2/kernel'
3
+ require_relative 'v2_2/math'
4
+
5
+ require_relative 'v2_2/prime'
3
6
  require_relative 'v2_2/vector'
4
7
 
5
8
  module Polyfill
@@ -0,0 +1,19 @@
1
+ module Polyfill
2
+ module V2_2
3
+ module Math
4
+ module ClassMethods
5
+ def log(*args)
6
+ if (base = args[1])
7
+ base = InternalUtils.to_f(base)
8
+ raise ::Math::DomainError, 'Numerical argument is out of domain - "log"' if base < 0
9
+
10
+ x = args[0]
11
+ return 0 / 0.0 if base == 0 && InternalUtils.to_f(x) == 0
12
+ end
13
+
14
+ super
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ module Polyfill
2
+ module V2_2
3
+ module Prime
4
+ module ClassMethods
5
+ def prime?(*args)
6
+ value = args.first
7
+ return false if value < 0
8
+
9
+ super
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
data/lib/polyfill/v2_3.rb CHANGED
@@ -7,6 +7,8 @@ require_relative 'v2_3/numeric'
7
7
  require_relative 'v2_3/string'
8
8
  require_relative 'v2_3/struct'
9
9
 
10
+ require_relative 'v2_3/prime'
11
+
10
12
  module Polyfill
11
13
  module V2_3
12
14
  end
@@ -0,0 +1,16 @@
1
+ module Polyfill
2
+ module V2_3
3
+ module Prime
4
+ module ClassMethods
5
+ def prime?(*args)
6
+ value = args.first
7
+ unless value.is_a?(::Integer)
8
+ raise ArgumentError, "Expected an integer, got #{value}"
9
+ end
10
+
11
+ super
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -3,13 +3,13 @@ module Polyfill
3
3
  module IPAddr
4
4
  def ==(*)
5
5
  super
6
- rescue
6
+ rescue ::IPAddr::InvalidAddressError
7
7
  false
8
8
  end
9
9
 
10
10
  def <=>(*)
11
11
  super
12
- rescue
12
+ rescue ::IPAddr::InvalidAddressError
13
13
  nil
14
14
  end
15
15
  end
data/lib/polyfill/v2_5.rb CHANGED
@@ -1,7 +1,11 @@
1
+ require_relative 'v2_5/dir'
1
2
  require_relative 'v2_5/hash'
2
3
  require_relative 'v2_5/integer'
3
4
  require_relative 'v2_5/kernel'
4
5
  require_relative 'v2_5/string'
6
+ require_relative 'v2_5/time'
7
+
8
+ require_relative 'v2_5/big_decimal'
5
9
 
6
10
  module Polyfill
7
11
  module V2_5
@@ -0,0 +1,13 @@
1
+ module Polyfill
2
+ module V2_5
3
+ module BigDecimal
4
+ def clone
5
+ self
6
+ end
7
+
8
+ def dup
9
+ self
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,27 @@
1
+ module Polyfill
2
+ module V2_5
3
+ module Dir
4
+ module ClassMethods
5
+ def children(dirname, encoding: Encoding.find('filesystem'))
6
+ entries(dirname, encoding: encoding) - %w[. ..]
7
+ end
8
+
9
+ def each_child(dirname, encoding: Encoding.find('filesystem'))
10
+ unless block_given?
11
+ return ::Enumerator.new do |yielder|
12
+ (entries(dirname, encoding: encoding) - %w[. ..]).each do |filename|
13
+ yielder.yield(filename)
14
+ end
15
+ end
16
+ end
17
+
18
+ (entries(dirname, encoding: encoding) - %w[. ..]).each do |filename|
19
+ yield(filename)
20
+ end
21
+
22
+ nil
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,8 +1,38 @@
1
+ require 'bigdecimal'
2
+
1
3
  module Polyfill
2
4
  module V2_5
3
5
  module Integer
4
6
  using Polyfill(Integer: %w[#ceil #floor #round #truncate], version: '2.4')
5
7
 
8
+ module ClassMethods
9
+ def sqrt(n)
10
+ n = InternalUtils.to_int(n)
11
+ if n < 0
12
+ raise Math::DomainError, 'Numerical argument is out of domain - "isqrt"'
13
+ end
14
+
15
+ res = 0
16
+ bit = 1 << ((n.size * 8) - 2)
17
+
18
+ bit >>= 2 while bit > n
19
+
20
+ while bit != 0
21
+ res_bit = res + bit
22
+ if n >= res_bit
23
+ n -= res_bit
24
+ res = (res >> 1) + bit
25
+ else
26
+ res >>= 1
27
+ end
28
+
29
+ bit >>= 2
30
+ end
31
+
32
+ res
33
+ end
34
+ end
35
+
6
36
  def ceil(*)
7
37
  super.to_i
8
38
  end
@@ -0,0 +1,24 @@
1
+ module Polyfill
2
+ module V2_5
3
+ module Time
4
+ module ClassMethods
5
+ def at(*args)
6
+ if args.size < 3 || args[2] == :microsecond || args[2] == :usec
7
+ return super(*args.first(2))
8
+ end
9
+
10
+ seconds, partial_seconds, unit = args
11
+
12
+ case unit
13
+ when :millisecond
14
+ super(seconds, partial_seconds * 1000)
15
+ when :nanosecond, :nsec
16
+ super(seconds, partial_seconds / 1000.0)
17
+ else
18
+ raise ArgumentError, "unexpected unit: #{unit}"
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module Polyfill
2
- VERSION = Gem::Version.new('1.1.0'.freeze)
2
+ VERSION = Gem::Version.new('1.2.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: 1.1.0
4
+ version: 1.2.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: 2018-02-23 00:00:00.000000000 Z
11
+ date: 2018-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -90,6 +90,8 @@ files:
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/math.rb
94
+ - lib/polyfill/v2_2/prime.rb
93
95
  - lib/polyfill/v2_2/vector.rb
94
96
  - lib/polyfill/v2_3.rb
95
97
  - lib/polyfill/v2_3/array.rb
@@ -98,6 +100,7 @@ files:
98
100
  - lib/polyfill/v2_3/hash.rb
99
101
  - lib/polyfill/v2_3/kernel.rb
100
102
  - lib/polyfill/v2_3/numeric.rb
103
+ - lib/polyfill/v2_3/prime.rb
101
104
  - lib/polyfill/v2_3/string.rb
102
105
  - lib/polyfill/v2_3/struct.rb
103
106
  - lib/polyfill/v2_4.rb
@@ -121,10 +124,13 @@ files:
121
124
  - lib/polyfill/v2_4/string_io.rb
122
125
  - lib/polyfill/v2_4/symbol.rb
123
126
  - lib/polyfill/v2_5.rb
127
+ - lib/polyfill/v2_5/big_decimal.rb
128
+ - lib/polyfill/v2_5/dir.rb
124
129
  - lib/polyfill/v2_5/hash.rb
125
130
  - lib/polyfill/v2_5/integer.rb
126
131
  - lib/polyfill/v2_5/kernel.rb
127
132
  - lib/polyfill/v2_5/string.rb
133
+ - lib/polyfill/v2_5/time.rb
128
134
  - lib/polyfill/version.rb
129
135
  - polyfill.gemspec
130
136
  homepage: ''